X

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 http://pkgs.repoforge.org/cstream/cstream-2.7.4-3.el6.rf.x86_64.rpm
rpm -Uvh http://pkgs.repoforge.org/perl-LockFile-Simple/perl-LockFile-Simple-0.207-1.el6.rf.noarch.rpm
rpm -Uvh http://download.openvz.org/contrib/utils/vzdump/vzdump-1.2-4.noarch.rpm
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
 CTID NPROC STATUS IP_ADDR HOSTNAME
 101 338 running 192.168.0.101 server1.example.com
 102 - stopped 192.168.0.102 server2.example.com
 103 - stopped 192.168.0.103 server3.example.com

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:

vzrestore
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
Tags: OpenVZ
Till Brehm:
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings