Compare commits

..

No commits in common. "44dc136c8a57dd70982cf725c9b2a5d2a083474a" and "e1ea936ffb9472fc5ec33bdfd549ad0141a4693a" have entirely different histories.

1 changed files with 7 additions and 26 deletions

View File

@ -3,7 +3,7 @@
helpFunction()
{
echo ""
echo "Usage: $0 -v VmName -t TargetHost -d TargetDataset -l LIMIT"
echo "Usage: $0 -v VmName -t TargetHost -d TargetDataset"
echo -e "\t-v Name of the vm to backup"
echo -e "\t-t Backup target host name"
echo -e "\t-s VM source zfs dataset"
@ -35,13 +35,6 @@ DATE=$(date "+%Y%m%d%H%M")
DATE30=$(date -d "-30day" "+%Y%m%d")
SNAPNAME="backup_$DATE"
abortFunction()
{
zfs set backup:success="false" $SRCZFS
zfs set backup:failed="$DATE" $SRCZFS
exit 1
}
VMDISKS=$(virsh domblklist $VM | egrep -o vd.)
DISKSPEC=""
for disk in $VMDISKS
@ -62,7 +55,7 @@ then
if [ $? -ne 0 ]
then
echo "VM snapshot creation failed" >&2
abortFunction
exit 1
else
echo "Snapshot created without --quiesce"
fi
@ -72,7 +65,7 @@ zfs snapshot "$SRCZFS"@"$SNAPNAME"
if [ $? -ne 0 ]
then
echo "ZFS snapshot creation failed" >&2
abortFunction
exit 1
fi
for disk in $VMDISKS
@ -86,7 +79,7 @@ do
if [[ $disk == *"snapshot"* ]]
then
echo "Snapshot deletion failed for $disk" >&2
abortFunction
exit 1
fi
done
@ -107,22 +100,10 @@ if [ $? -eq 0 ]
then
zfs set backup:success="true" $SRCZFS
zfs set backup:date="$DATE" $SRCZFS
zfs destroy "$SRCZFS"@"$LASTSNAP"
else
abortFunction
zfs set backup:success="false" $SRCZFS
zfs set backup:failed="$DATE" $SRCZFS
fi
zfs destroy tank/snapshots/$VM
# cleanup old backups
OLDSNAPS=$(ssh $DESTHOST zfs list -r -t snapshot -o name $DESTZFS 2>/dev/null | grep $DATE30)
if [ ${#OLDSNAPS} -gt 0 ]
then
for oldsnap in $OLDSNAPS
do
ssh $DESTHOST sudo zfs destroy $oldsnap
done
else
echo "No old snapshots to cleanup"
fi