add cleanup

This commit is contained in:
Jochen Welzel 2021-01-06 10:18:14 +01:00
parent 8c5cab92f7
commit 956f2e65f6

View File

@ -29,7 +29,7 @@ then
helpFunction
fi
DATE=$(date "+%Y%m%d")
DATE=$(date "+%Y%m%d%H%M")
DATE30=$(date -d "-30day" "+%Y%m%d")
SNAPNAME="backup_$DATE"
@ -40,6 +40,9 @@ do
DISKSPEC+="--diskspec $disk,file=/srv/snapshots/$VM/$VM-$disk-$SNAPNAME.qcow2,snapshot=external "
done
# create snapshot dataset
zfs create tank/snapshots/$VM
virsh snapshot-create-as --domain $VM --name $SNAPNAME --quiesce --atomic --disk-only $DISKSPEC > /dev/null
if [ $? -ne 0 ]
then
@ -68,5 +71,17 @@ do
fi
done
zfs send "$SRCZFS"@"$SNAPNAME" | pv -L 500M | ssh $DESTHOST sudo zfs recv -F $DESTZFS
virsh snapshot-delete $VM $SNAPNAME --metadata
zfs send "$SRCZFS"@"$SNAPNAME" | pv -L 500M | ssh $DESTHOST sudo zfs recv -F $DESTZFS
if [ $? -eq 0 ]
then
zfs set backup:success="true" $SRCZFS
zfs set backup:date="$DATE" $SRCZFS
else
zfs set backup:success="false" $SRCZFS
zfs set backup:failed="$DATE" $SRCZFS
fi
zfs destroy tank/snapshots/$VM