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