To properly migrate an old openvz container to a new lxc container can be a bit tricky, but I finally succeeded to find a proper way with a minimal downtime.
In my examples the container ID is 108.
It starts with a vzdump of the current container:
vzdump 108 --remove 1 --mode snapshot --compress lzo --storage backup09 --node clust-10 --bwlimit 0 --size 8192
–remove 1 says it’s allowed to remove the previous dump, if there is any
–mode snapshot says it’s making a live dump of a running container (no downtime)
–compress lzo is a light but efficient compress method
–bwlimit 0 is important if you can handle speeds over 80000 kb/s, which is default bwlimit
–size 8192 will fix input/output errors on certain lvm storages with low free diskspace
Above command will result in a file which you can use later in the pct restore command:
pct restore 108 $(ls -1r /mnt/pve/backup09/dump/vzdump-openvz*108* | head -n1) --storage ssd --onboot 1 --net1 name=eth0,bridge=vmbr0 --net2 name=eth2,bridge=vmbr2
This command will restore the back-up in to a new lxc container on the new node. The command will extract the last found dump of that container ID to the storage called ‘ssd’ (in our case the CEPH filesystem). It will also add some network devices and change the setting to start at boot.
Above command you can run during daytime, because some containers will take hours to pack and unpack, it can be handy to do so.
After that you can mount the new container with:
pct mount 108
Now you can access the files directly on this path:
/var/lib/lxc/108/rootfs/home
This makes it possible to update certain files, to make sure you start the container with the latest data.
So next we are going to stop the old container:
vzctl stop 108
After that we need to rsync the data from the old node to the new node, like:
rsync --stats -avz /var/lib/vz/private/108/home/ root@10.0.0.61:/var/lib/lxc/108/rootfs/home
rsync --stats -avz /var/lib/vz/private/108/var/lib/mysql/ root@10.0.0.61:/var/lib/lxc/108/rootfs/var/lib/mysql
rsync --stats -avz /var/lib/vz/private/108/var/log/ root@10.0.0.61:/var/lib/lxc/108/rootfs/var/log
rsync --stats -avz /var/lib/vz/private/108/etc/ root@10.0.0.61:/var/lib/lxc/108/rootfs/etc
You can see that 10.0.0.61 is the IP of the new node. It will rsync all the data in just a couple of minutes, of course depending on the age of the dump.
After adding the network interfaces (if not done already by the restore command), you can unmount and start the new lxc container on the new node:
pct unmount 108
pct start 108
If you are lucky everything starts and works like a charm 🙂