OpenVZ/Proxmox - pre-backup all container dump script

18-01-2015 | Remy van Elst

Table of Contents

This simple script creates a vzdump of all the OpenVZ containers on a machine. It can be used before an actual backup, in my case the actual backup excludes the container path /var/lib/vz/private. This because a dump is easier to backup because it has much less files in it.

If I include the container path my backups take about 40% longer to run then with only the dumps enabled.

Do note that the VM's by default are stopped a very short while. The mode is suspend, which means that first an online copy of all the files is performed, then the VM is stopped and the remaining changed files are synced. Afterwards the VM is booted again.

The mode can also be snapshot, then it will take an LVM snapshot without any downtime. You do need to have enough free space on your LVM volume.

The last mode is stop, which will shut down the VM before the dump and boot it up afterwards. Long downtime includes.


# Author: Remy van Elst,
# Small script to dump OpenVZ VM's before a backup. (pre-backup scripts)
# License: GNU GPLv3

BACKUPDIR="/var/backups/vz/$(date +%Y%m%d)"
if [[ ! -d "$BACKUDIRP" ]]; then
    mkdir -p "$BACKUPDIR"

vzdump "${vmid}" --stdexcludes --mode=${MODE} --dumpdir=${BACKUPDIR} --compress=gzip --all

My backup software allows me to run scripts before and after a backup, so called pre and post backup scripts. This is a pre-backup script. You can also have a post backup script which cleans up these temp dump files after the backup has succeeded.

Tags: bash  kvm  openvz  proxmox  proxmox-ve  software  ssh  virtualization  vzdump