Skip to main content

Raymii.org Raymii.org Logo

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

OpenVZ/Proxmox - pre-backup all container dump script

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


❗ This post is over nine years old. It may no longer be up to date. Opinions may have changed.

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.

Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:

I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!

Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.

You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $100 credit for 60 days.

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