In OpenVZ, containers also known as Virtual Machine or VPS. OpenVZ is a Linux based Kernel virtualization technology developed by SWSoft for its commercial product Virtuozzo. 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.
In this tutorial I will show how you can backup OpenVZ container using vzdump command.
Follow the below steps to backup OpenVZ container.
Step #1 : Download and Install vzdump command
First of all install vzdump command on your system if not installed. Follow the below download and install vzdump 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
Step #2 : Backup OpenVZ Virtual Machine (Container)
Now, find the container ID of the virtual machine. Follow the below command to find the container ID.
Find Container ID
# vzlist -a
You will get some output like below:
CTID NPROC STATUS IP_ADDR HOSTNAME 101 338 running 192.168.0.101 vsrv01.example.com 102 - stopped 192.168.0.102 vsrv02.example.com 103 - stopped 192.168.0.103 vsrv03.example.com
You can find the container ID in line CTID as shown above.
Next create the directory where you want to store backup. In my case I have created in /home/backup. You can use another directory, just make sure you have enough space in that partitions where you want to store backup.
Create Backup Directory
# mkdir /home/backup # chmod 700 /home/backup # chown root:root /home/backup
Create Container Backup
Now create backup of your virtual machine (container) with ID 101 as shown below.
# vzdump --compress --dumpdir /home/backup 101
Create All Containers Backup
If you want to create all containers backup use –all option with vzdump command as shown below.
# vzdump --compress --dumpdir /home/backup --all
—compress – Dump the backup in compress format such as tar.gz to save space.
—dumpdir – Directory location where you want to store backup.
Step #3 : Restore Backup Using vzrestore Command
After backup created successfully now restore with the backup using vzrestore command as shown below.
# vzrestore usage: /usr/sbin/vzrestore [OPTIONS] --force overwrite existing conf file, private and root directory
I am going to restore virtual machine 101 from out backup under the new ID 104.
# vzrestore /home/backup/vzdump-101.tgz 104