User Tools

Site Tools


migrate_openvz

Migrate OpenVZ to another OpenVZ host without vzdump (using rsync)

BuyVM does not support creating or restoring vzdump backups. If you'd like to attempt a semi-automated method of migrating OpenVZ without vzdump, read on.

Warning! This can easily hose your target system, especially if the transfer is disrupted.

Why?

Please take care to back up your data first. Preferably from both systems.

Why?

I cannot stress enough how easily this can leave your system in a state where it needs to be re-imaged.

Why?

Never attempt to migrate an OpenVZ to a dedicated or KVM unless you know what you're doing.

Why?

This method works best run from the openvz system console. Most vps providers have a shell console you can access. Log into that shell on both machines and go through each active service and turn it off. Using kill may cause open files to be left in an inconsistent state, especially for SQL servers, so please shut them down gracefully. The only active service that should be running on the target machine is ssh.

Make sure rsync is installed on both the source and destination machines. This utility is usually installed by default.

If root login is disabled, enable root login for both the source and destination machines.

Create the file /dev/shm/exclude.txt with the following contents:

/dev/*
/proc/*
/sys/*

If you have any large data folders that can be copied after the core system has been transferred, exclude them now as well.

Run the following command on the source host:

rsync -avHAXWcSP --numeric-ids --progress --del --exclude-from=/dev/shm/exclude.txt / root@<DESTINATION_HOST>:/

Now pray that your connection is not interrupted.

If you were lucky, your entire system is now migrated to your new host. If you exempted large data folders before, remove them from the exclude.txt file now, and re-run the rsync command. This time, you will have to log in with your old vps's credentials. It should now transfer your large files only.

You may get a warning when re-running rsync that your sshd's host key has changed, that's normal. The previous command copied the host key from your old host.

Run the reboot command to restart the destination host.

A faster copy: tar then rsync

Since a linux system is largely small files, it is usually faster to tar them up before transfer as rsync checks each file. Instead of checking each file, this merely replaces everything it finds from the old system on the new system.

Caveat: This does not attempt to restore hardlinks. If you make use of hardlinks, you may find them unlinked in the result. Many backup storage methods use hardlinks to save space.

For the most part, the instructions are the same with the following exception. For the first pass, instead of rsync, run the following tar command:

tar cvpPSf - --numeric-owner -X /dev/shm/exclude.txt / | ssh root@<DESTINATION_HOST> "tar xpPSf - --numeric-owner -C /"

This will in-situ copy all non-excluded files to the remote host. Then run a second pass with rsync to clean up the old files as well as verify your original transfer is completed successfully.

You may get a warning here that your sshd's host key has changed, that's normal. The previous command copied the host key from your old host.

rsync -avHAXWcSP --numeric-ids --progress --del --exclude-from=/dev/shm/exclude.txt / root@<DESTINATION_HOST>:/

After everything is copied, restart your vps as normal

migrate_openvz.txt · Last modified: 2013/03/24 07:24 by Andrew Domaszek