rsyncing two hard drives on two servers

The current situation: I have two servers at online.net. I have to transfer all the datas from one server to another.

Let's rsync all that.

First, put the old server in rescue mode. Mount the disk on /mnt/old On the new server, allow root to connect to ssh by setting PermitRootLogin to Yes in /etc/ssh/sshd_config. Mount through sshfs the whole disk of the new server.

old-server# sshfs root@new-server:/ /mnt/new

Open a new tmux/screen to do the copy and start the replication

old-server-rescue# cd /mnt/old
old-server-rescue /mnt/old# rsync -a -H -R -A -X --devices --specials -t --delete --progress --human-readable . /mnt/new


** and wait a few hours **

Beware, as /mnt/old/dev is not fully populated, devices on the new server will be deleted. Devices like /dev/urandom won't be available and further ssh connections wont be possible.

Once the rsync is done, put the new server in rescue mode. Mount the disk :

rescue-new-server# mount /dev/sda1 /mnt

Bind some extra directories :

rescue-new-server# for i in dev proc sys; do mount -o bind /$i /mnt/$i; done

And chroot in /mnt:

rescue-new-server# chroot /mnt
new-server#

Modify the folowing files :

  • /etc/udev/rules.d/70-persistent-net.rules and update the new mac address for eth0
  • /etc/fstab if needed to update the disk's UUID (not necessary if you use /dev/sda1 as device name)
  • /etc/network/interface to update the new ip address/gateway/...

Install grub and update the configuration file:

new-server# grub-install /dev/sda
new-server# update-grub

Once done, exit the chroot and umount everything

new-server# exit
rescue-new-server# umount /mnt/dev /mnt/proc /mnt/sys /mnt

And reboot. Your new server should be up in no time with all your datas

Haut de page