Backup a running container using vzdump

PDF
Vzdump is a tool to make consistent snapshots of running OpenVZ containers. Vzdump stores the backup on the disk in a single file, a tar archive, which also includes the CT configuration files. This archive can be used to clone or to restore a system.

There are a few items required for installing vzdump for OpenVZ on CentOS.

First we need Simple Locking file I/O library for Perl and cstream. Both packages are available at the Dag Wiers repository. If you haven't setup the Dag Wiers repository follow the instructions explained on this website. Next install both rpm's using yum:
yum install cstream perl-LockFile-Simple
Download and install vzdump:
rpm -ivh "http://ftp.openvz.org/contrib/utils/vzdump/vzdump-1.2-4.noarch.rpm"
How to backup a container with minimal downtime?

To backup a running container with minimal downtime we will use the --suspend switch. This will create a backup, suspend the contain, use rsync to backup the changed files since the start of the backup and resume the container. The downtime is minimal (depending on the situation it can be a few seconds).

To make a dump of container CT 104 to the default dump directory (/vz/dump) and send an email with the results run:
vzdump --suspend 104 --mailto 
  This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 
In the output you will see that the downtime for this example container was just 8 sec and total backup-time 4m55s.
104: Jul 1 10:24:10 INFO: Starting Backup of VM 104 (openvz)
104: Jul 1 10:24:10 INFO: CTID 104 exist mounted running
104: Jul 1 10:24:10 INFO: status = CTID 104 exist mounted running
104: Jul 1 10:24:10 INFO: backup mode: suspend
104: Jul 1 10:24:10 INFO: bandwidth limit: 10240 KB/s
104: Jul 1 10:24:10 INFO: starting first sync /vz/private/104/ to /vz/dump/vzdump-openvz-104-2010_07_1-10_24_10.tmp
104: Jul 1 10:26:58 INFO: Number of files: 62319
104: Jul 1 10:26:58 INFO: Number of files transferred: 52451
104: Jul 1 10:26:58 INFO: Total file size: 1355544361 bytes
104: Jul 1 10:26:58 INFO: Total transferred file size: 1173437858 bytes
104: Jul 1 10:26:58 INFO: Literal data: 1173437934 bytes
104: Jul 1 10:26:58 INFO: Matched data: 0 bytes
104: Jul 1 10:26:58 INFO: File list size: 1369951
104: Jul 1 10:26:58 INFO: File list generation time: 2.049 seconds
104: Jul 1 10:26:58 INFO: File list transfer time: 0.000 seconds
104: Jul 1 10:26:58 INFO: Total bytes sent: 1177509896
104: Jul 1 10:26:58 INFO: Total bytes received: 1329591
104: Jul 1 10:26:58 INFO: sent 1177509896 bytes received 1329591 bytes 6996080.04 bytes/sec
104: Jul 1 10:26:58 INFO: total size is 1355544361 speedup is 1.15
104: Jul 1 10:26:58 INFO: first sync finished (168 seconds)
104: Jul 1 10:26:58 INFO: suspend vm
104: Jul 1 10:26:58 INFO: Setting up checkpoint...
104: Jul 1 10:26:58 INFO: suspend...
104: Jul 1 10:26:58 INFO: get context...
104: Jul 1 10:26:58 INFO: Checkpointing completed succesfully
104: Jul 1 10:26:58 INFO: starting final sync /vz/private/104/ to /vz/dump/vzdump-openvz-104-2010_07_1-10_24_10.tmp
104: Jul 1 10:27:06 INFO: Number of files: 62319
104: Jul 1 10:27:06 INFO: Number of files transferred: 6
104: Jul 1 10:27:06 INFO: Total file size: 1355544437 bytes
104: Jul 1 10:27:06 INFO: Total transferred file size: 267957666 bytes
104: Jul 1 10:27:06 INFO: Literal data: 0 bytes
104: Jul 1 10:27:06 INFO: Matched data: 267957666 bytes
104: Jul 1 10:27:06 INFO: File list size: 1369951
104: Jul 1 10:27:06 INFO: File list generation time: 2.351 seconds
104: Jul 1 10:27:06 INFO: File list transfer time: 0.000 seconds
104: Jul 1 10:27:06 INFO: Total bytes sent: 163285
104: Jul 1 10:27:06 INFO: Total bytes received: 162394
104: Jul 1 10:27:06 INFO: sent 163285 bytes received 162394 bytes 191256.35 bytes/sec
104: Jul 1 10:27:06 INFO: total size is 1355544437 speedup is 833.83
104: Jul 1 10:27:06 INFO: final sync finished (8 seconds)
104: Jul 1 10:27:06 INFO: resume vm
104: Jul 1 10:27:06 INFO: Resuming...
104: Jul 1 10:27:06 INFO: vm is online again after 8 seconds
104: Jul 1 10:27:06 INFO: creating archive '/vz/dump/vzdump-openvz-104-2010_07_1-10_24_10.tar'
104: Jul 1 10:29:04 INFO: Total bytes written: 1234862080 (1.2GiB, 10MiB/s)
104: Jul 1 10:29:04 INFO: archive file size: 1.15GB
104: Jul 1 10:29:05 INFO: Finished Backup of VM 104 (00:04:55)
To create a backup with no downtime you can run vzdump to create a LVM2 snapshot. Therefore you need to have at least 512Mb free space in the LVM Volume Group, but depending on your system it might be more. 1Gb will be sufficient.

To create a LVM snapshot to the default dump directory with gzip compression, run:
vzdump --snapshot 104 --mailto 
  This e-mail address is being protected from spambots. You need JavaScript enabled to view it
  --compress
How to restore from a backup?

To restore from a dump, run:
vzdump --restore /vz/dump/vzdump-openvz-104-2010_07_1-10_24_10.tar 104

How to clone a system?


Follow the steps as described above for creating a backup of a container.
To make a clone of this backup file, run vzdump and specify a new container-id (cid) and edit the configuration for the newly created container with the vzctl command so this new container will get a new ip-address, new host-name etc as this container will have exact the same configuration as the one from which it was cloned.
vzdump --restore /vz/dump/vzdump-openvz-104-2010_07_1-10_24_10.tar 110

To change the configuration from the original. ie:
vzctl set 110 --ipdel [original-ip] --ipadd [new-ip] --hostname newhost.yourdomain.com --save

If necessary you can also change other parameters, see man vzctl for more details.
 

Search






You are here: Home Howtos and FAQs Virtualization Backup a running container using vzdump