Quantcast
Channel: Tutorials — LowEndTalk
Viewing all articles
Browse latest Browse all 1028

OpenVZ/Proxmox pre-backup dump all container script

$
0
0

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.

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.

Source: https://raymii.org/s/software/OpenVZ_Proxmox_-_pre-backup_all_container_dump_script.html


Viewing all articles
Browse latest Browse all 1028

Trending Articles