Apr 272014
 

I recently moved a server using rsync only. This is how I did it:

I used the same OS on both (Debian), both fully upgraded and rescue mode (should work in running mode, too).

Before I had to set locales on the new server using:

export LANG=es_ES.UTF-8
dpkg-reconfigure locales

On my source I checked the installed packages using:
dpkg --get-selections > /tmp/dpkg.txt

The dpkg.txt file can be moved to the new server and the packages may be installed using:

dpkg --set-selections < /tmp/dpkg.txt
apt-get -u dselect-upgrade

If you get warnings like “warning: package foobar not in database“, try

sudo apt-get install dselect
sudo dselect 
   -> Update
   -> Install

Nearly done. Now you need to move all the files. Create an exclude textfile (my_exclude) with these entries (or other files that you don’t want to move). I used this:

/var/cache/apt/
/var/cache/davfs2/
/media/
/mnt
/sys/
/boot/
/lib/modules
/etc/modules
/etc/lilo.conf
/etc/fstab
/etc/mtab
/proc
/dev
lost+found/
/var/log
/etc/network/interfaces
/etc/network/
/etc/networks
/etc/hosts

And finally rsync the all the data, except the exclude files using (execute on old server)
rsync --progress -avz --exclude-from=/root/my_exclude <newserver_ip>:/ /

After that I would manually check for the old IP in /etc/ using
grep -R <old_ip> /etc/*
and manually verify and replace it (in vi e.g. :%s/oldip/newip/g)

To configure grub, you simple reinstall it from the rescue system:

mount -t proc proc proc/
mount -t sysfs sys sys/
mount -o bind /dev dev/
mount -t devpts pts dev/pts/
dpkg-reconfigure grub-pc

Sounds harder than it is.