How to Backup OpenVZ Containers with vzdump on CentOS

OpenVZ is a Linux-based Kernel virtualization technology developed by SWSoft for its commercial product Virtuozzo. The modified Linux Kernel and the system utilities are released under an OpenSource license. Vzdump is a shell-based backup program for OpenVZ virtual machines. It is made for containers that use the traditional "simfs" filesystem, it can not be used for containers with "ploop" filesystem. This guide is written on CentOS 6.

Installation of vzdump

Run the following commands to download and install the RPM packages.

rpm -Uvh
rpm -Uvh
rpm -Uvh
ln -s /usr/share/perl5/PVE/ /usr/lib/perl5/5.8.8/PVE

Backup an OpenVZ virtual machine

First we will have to find the container ID of the virtual machine. You can get a list of all virtual machines on the local server with the vzlist command:

vzlist -a

The output will be similar to this:

vzlist -a
 101 338 running
 102 - stopped
 103 - stopped

Now create the directory where the backup shall be stored. I will use /home/backup in this case. You may use any directory, just ensure that you have enough free space on the partitions where the backup directory resides.

mkdir /home/backup
chmod 700 /home/backup
chown root:root /home/backup

Finally, I will create a backup of the virtual machine with ID 101:

vzdump --compress --dumpdir /home/backup 101

The option "--compress" instructs vzdump to store the backup as tar.gz format to save space. To create a backup of all virtual machines, use this command instead:

vzdump --compress --dumpdir /home/backup --all

Restore a vzdump Backup

The backup that we created with vzdump can be restored with the vzrestore command. the Syntax is as follows:

usage: /usr/sbin/vzrestore [OPTIONS] <ARCHIVE> <VMID>

 --force overwrite existing conf file, private and root directory

Vzdump restore example

Restore the virtual machine 101 from our backup under the new ID 104:

vzrestore /home/backup/vzdump-101.tgz 104