Skip to main content

Raymii.org Logo (IEC resistor symbol) logo

Quis custodiet ipsos custodes?
Home | About | All pages | RSS Feed | Gopher

OpenVZ/Proxmox - pre-backup all container dump script

Published: 18-01-2015 | Author: Remy van Elst | Text only version of this article


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 you like this article, consider sponsoring me by trying out a Digital Ocean VPS. With this link you'll get $100 credit for 60 days). (referral link)

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.

Script

#!/bin/bash
# Author: Remy van Elst, https://raymii.org
# Small script to dump OpenVZ VM's before a backup. (pre-backup scripts)
# License: GNU GPLv3

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

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