Home Company Services Portfolio Contact us nav spacer

Migrating an entire linux-vserver virtual server to another machine

by Izak Burger posted on Jun 23, 2009 12:42 PM last modified Jun 23, 2009 12:42 PM —

I always forget the exact rsync command used for this purpose. Here it is for me and the rest of the world too.

The method I use is to rsync the whole machine to the new location while it is still running, then take it down, rsync it again, and bring it up in the new location.

Because we do not allow root logins, we also need to add sudo to the mix, and a few other options. The whole command is:

  rsync -aH -v -e ssh --rsync-path 'sudo rsync' \
  --numeric-ids --partial --delete \
  /var/lib/vservers/vsname/ \
  myuser@remotehost:/var/lib/vservers/vsname/

The --rsync-path option is required to use sudo on the other end. --numeric-ids is important, otherwise rsync resolves uid's using /etc/passwd and /etc/group, which may differ on the host. -a puts it in archive mode, which preserves links, permissions and ownership, and -H also preserves hard links. --delete tells rsync to delete files on the remote end that are no longer available locally.

You also need to set up the required files in /etc/vservers of course.