#!/bin/bash
# Creates a snapshot of the volume storing the KVM images, and then
# using that snapshot copies the images. The benefit of using a snapshot
# (as opposed to copying the images) is that the VM does not need to be
# shutdown.
# Include appropriate paths (since cron doesn't use your normal environment)
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
# The date of the backup
bkpdate=`date +%Y-%m-%d`
# Create a LVM snapshot of the var LV
lvcreate -L 70G -s -n varsnap /dev/fedora_host/var
# Mount the snapshot
mount /dev/fedora_host/varsnap /mnt/snapshot
# Copy the KVM images
tar --create --sparse --file /backup/guest1-${bkpdate}.img.tar /mnt/snapshot/vm/guest1.img
tar --create --sparse --file /backup/guest2-${bkpdate}.img.tar /mnt/snapshot/vm/guest2.img
# Remove the snapshot
umount /mnt/snapshot
lvremove -f /dev/fedora_host/varsnap
Posted by L3UNIX to L3UNIX's deck (2016-03-11 22:58)