add some improvements

This commit is contained in:
Jochen Welzel 2021-01-07 12:10:48 +01:00
parent 44dc136c8a
commit 7ac1988d75

View File

@ -35,6 +35,8 @@ DATE=$(date "+%Y%m%d%H%M")
DATE30=$(date -d "-30day" "+%Y%m%d")
SNAPNAME="backup_$DATE"
echo "$(date +%Y-%m-%d_%H:%M): Starting Backup of $VM"
abortFunction()
{
zfs set backup:success="false" $SRCZFS
@ -93,21 +95,32 @@ done
virsh snapshot-delete $VM $SNAPNAME --metadata
SUCCESS=$(zfs get backup:success -H -o value $SRCZFS)
LASTBACKUP=$(zfs get backup:date -H -o value $SRCZFS)
if [[ $SUCCESS == "true" ]]
then
LASTBACKUP=$(zfs get backup:date -H -o value $SRCZFS)
LASTSNAP="backup_$LASTBACKUP"
echo "Sending incremental snapshot from $LASTSNAP"
zfs send -R -i "$SRCZFS"@"$LASTSNAP" "$SRCZFS"@"$SNAPNAME" | pv -L $LIMIT | ssh $DESTHOST sudo zfs recv -F $DESTZFS
else
echo "Sending full snapshot"
zfs send -R "$SRCZFS"@"$SNAPNAME" | pv -L $LIMIT | ssh $DESTHOST sudo zfs recv -F $DESTZFS
if [[ $LASTBACKUP != "-" ]]
then
LASTSNAP="backup_$LASTBACKUP"
echo "Trying to send incremental snapshot from $LASTSNAP"
zfs send -R -i "$SRCZFS"@"$LASTSNAP" "$SRCZFS"@"$SNAPNAME" | pv -L $LIMIT | ssh $DESTHOST sudo zfs recv -F $DESTZFS
else
echo "Sending full snapshot"
zfs send -R "$SRCZFS"@"$SNAPNAME" | pv -L $LIMIT | ssh $DESTHOST sudo zfs recv -F $DESTZFS
fi
fi
if [ $? -eq 0 ]
then
zfs set backup:success="true" $SRCZFS
zfs set backup:date="$DATE" $SRCZFS
zfs destroy "$SRCZFS"@"$LASTSNAP"
if [ -n $LASTSNAP ]
then
echo "Deleting old ZFS snapshot $LASTSNAP"
zfs destroy "$SRCZFS"@"$LASTSNAP"
fi
else
abortFunction
fi