Now that I’ve been using OpenVZ for several months I thought it would be a good time to devote a few cycles to putting together a backup routine for the 10+ OpenVZ VEs that I’ve setup. Here is the procedure I put together to backup one of my VEs. I should mention that all my VEs make use of automounts, and through experimentation I figured out that I need to stop the automounter while I’m performing a backup of a VE. From my HN I determined that this was the minimal number of commands I could accomplish a backup of a single VE.
1 2 3 4 | vzctl exec 101 /etc/init.d/autofs stop # stop automounter vzdump --compress --suspend 101 # backup VE(Virtual Environment) 101 vzctl exec 101 /etc/init.d/autofs start # start automounter mv vzdump-101.log vzdump-101.tgz /mnt/vz_backups/ # move backed up file to on-line storage area |
Here is the full transcript from a backup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | % vzctl exec 101 /etc/init.d/autofs stop Stopping automount: [ OK ] % vzdump --compress --suspend 101 INFO: Starting new backup job - vzdump --compress --suspend 101 INFO: Starting Backup of VM 101 (openvz) INFO: status = CTID 101 exist mounted running INFO: starting first sync /vz/private/101 to /var/tmp/vzdumptmp22651 INFO: Number of files: 35178 INFO: Number of files transferred: 25940 INFO: Total file size: 800591555 bytes INFO: Total transferred file size: 616512883 bytes INFO: Literal data: 616512883 bytes INFO: Matched data: 0 bytes INFO: File list size: 712364 INFO: File list generation time: 0.001 seconds INFO: File list transfer time: 0.000 seconds INFO: Total bytes sent: 618585522 INFO: Total bytes received: 679718 INFO: sent 618585522 bytes received 679718 bytes 10069353.50 bytes/sec INFO: total size is 800591555 speedup is 1.29 INFO: first sync finished (61 seconds) INFO: suspend vps INFO: Setting up checkpoint... INFO: suspend... INFO: get context... INFO: Checkpointing completed succesfully INFO: final sync /vz/private/101 to /var/tmp/vzdumptmp22651 INFO: Number of files: 35178 INFO: Number of files transferred: 0 INFO: Total file size: 800591555 bytes INFO: Total transferred file size: 0 bytes INFO: Literal data: 0 bytes INFO: Matched data: 0 bytes INFO: File list size: 712364 INFO: File list generation time: 0.001 seconds INFO: File list transfer time: 0.000 seconds INFO: Total bytes sent: 716728 INFO: Total bytes received: 4363 INFO: sent 716728 bytes received 4363 bytes 480727.33 bytes/sec INFO: total size is 800591555 speedup is 1110.25 INFO: final sync finished (1 seconds) INFO: resume vps INFO: Resuming... INFO: vps is online again after 3 seconds INFO: creating archive '/vz/dump/vzdump-101.dat' (/var/tmp/vzdumptmp22651/101) INFO: Total bytes written: 641587200 (612MiB, 11MiB/s) INFO: file size 201MB INFO: Finished Backup of VM 101 (00:02:02) % vzctl exec 101 /etc/init.d/autofs start Starting automount: [ OK ] % mv vzdump-101.log vzdump-101.tgz /mnt/vz_backups/. |
I put together this one-liner which will handle the backing up of all 11 of my VEs.
1 2 | for i in `seq 101 111`;do vzctl exec $i /etc/init.d/autofs stop; vzdump --compress --suspend $i; vzctl exec $i /etc/init.d/autofs start;done mv vzdump-*.tgz /mnt/vz_backups/. |
