Things to remember to backup or copy when migrating servers

A new version of your operating system just got released and you want to have a fresh new install, or you want to migrate all of your data to another machine. There are so much stuff to backup that you don’t even know where to start?
I will try to list the most common stuff (on a web-server) to backup or copy somewhere when you want to do a server migration.

This tutorial is targeted to Ubuntu systems, but can easily apply to Debian or other distributions.
Please also note that this should only be used as a guide, I do not guarantee that this will save all of your configuration. NO WARRANTY !

  • First, make sure you execute each command as root, or use sudo.
  • Make a secret temporary folder to store your backup and cd into it:
    cd "$(mktemp -d)"
  • The /home folder: just tar everything, as root type:
    tar --preserve -cvjf home.tar.bz2 /home
  • Backup /root
    tar --preserve -cvjf root.tar.bz2 /root
  • Backup users, passwords and groups:
    • users are in /etc/passwd and /etc/shadow
    • groups are in /etc/group and /etc/gshadow,

    JUST take the lines containing users/groups that YOU created (usually they have a uid >= 1000)!

  • Backup crontabs, and atjobs:
    tar --preserve -cvjf etc_crontab.tar.bz2 /etc/crontab
    tar --preserve -cvjf spool_crontabs.tar.bz2 /var/spool/cron/crontabs/
    tar --preserve -cvjf spool_atjobs.tar.bz2 /var/spool/cron/atjobs/
  • Backup users’ email:
    tar --preserve -cvjf email.tar.bz2 /var/mail/
  • Websites:

    tar --preserve -cvjf www.tar.bz2 /var/www/
  • Backup needed config files in /etc/:
    • Apache2 vhosts:
      tar --preserve -cvjf vhosts.tar.bz2 /etc/apache2/sites-available/
    • Networking configuration:
      tar --preserve -cvjf network.tar.bz2 /etc/network/interfaces /etc/hosts*
    • Postfix configuration:
      tar -cvjf postfix.tar.bz2 /etc/postfix/*.cf
    • Anything else you see in /etc/ and you wish to keep…
  • Backup MySQL databases, users and privileges:
    mysqldump -uroot -p --databases mydb1 somedb2 anotherdb3 > db.sql
    mysqldump -nt -uroot -p -w"User NOT LIKE 'root' AND User NOT LIKE 'debian%'" mysql user db > users_privs.sql

I’m sure you can figure out where to put everything back on the destination server.

One Reply to “Things to remember to backup or copy when migrating servers”

Leave a Reply