====== Burp - backup and restore program ======
[[https://burp.grke.org/|BURP]] is a powerful backup and restore tool.
===== backup lvm snapshots =====
I backup virtual machines from hypervisors using burp and lvm (thin) snapshots.
backup_script_pre=/etc/burp/pre_backup.sh
backup_script_post=/etc/burp/post_backup.sh
**/etc/burp/pre_backup.sh** and **/etc/burp/post_backup.sh** are both symlinks to **/etc/burp/backup_lvm.sh**
#!/bin/sh
set -e
MNT=/mnt/burp
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
SUFFIX=_burp
MNT=/mnt/burp
snapshot() {
vg=$2
lv=$3
lvsnap=${4:-$3}$SUFFIX
mnt=$MNT/${4:-$3}
partition=$5
if test -z "$vg" -o -z "$lv"; then
echo "bad params: $@" 1>&2
exit 1
fi
if [ "$1" = "pre" ]; then
mkdir -p $mnt
thin=$(lvs $vg/$lv | tail -n 1 | awk '{ print $5 }')
if [ -n "$thin" ]; then
lvcreate -kn -n $lvsnap -s $vg/$lv
else
lvcreate -L2G -s -n $lvsnap $vg/$lv
fi
#lvchange -ay -K $vg/$lvsnap
sleep 1
if test -n "$partition"; then
kpartx -avs /dev/mapper/$vg-$lvsnap
dev=/dev/mapper/$vg-$lvsnap$partition
else
dev=/dev/mapper/$vg-$lvsnap
fi
mount $dev $mnt
elif [ "$1" = "post" ]; then
umount -f $mnt || true
if test -n "$partition"; then
kpartx -d /dev/mapper/$vg-$lvsnap || true
fi
lvremove -f $vg/$lvsnap || true
fi
}
script=$(basename $0)
if [ "$script" = "pre_backup.sh" ]; then
action=pre
elif [ "$script" = "post_backup.sh" ]; then
action=post
else
echo "bad invocation $0" 1>&2
exit 1
fi
while IFS= read -r line; do
echo "$line" | grep -q '^#' && continue
test -z "$line" && continue
snapshot $action $line
done < "$(dirname $0)/backup_lvm.conf"
The file reads its config from **/etc/burp/backup_lvm.conf** which list the logical volumes to be snapshoted and mounted before burp runs, for instance:
# VGNAME LVNAME (MNT_NAME) (PARTITION)
vg0 root
vg0 vm_build build 1
vg0 vm_k2 k2 1
vg0 vm_k2_data k2_data
vg0 vm_db db 1
vg0 vm_db_postgres db_postgres
vg0 vm_db_mysql db_mysql
vg0 vm_db_logs db_logs
Then on server side, just **include=** mountpoint from **/mnt/burp** to the list of filesystems to be backup by burp.