add some improvements
This commit is contained in:
parent
44dc136c8a
commit
7ac1988d75
@ -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
|
||||||
echo "Sending full snapshot"
|
if [[ $LASTBACKUP != "-" ]]
|
||||||
zfs send -R "$SRCZFS"@"$SNAPNAME" | pv -L $LIMIT | ssh $DESTHOST sudo zfs recv -F $DESTZFS
|
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
|
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
|
||||||
zfs destroy "$SRCZFS"@"$LASTSNAP"
|
if [ -n $LASTSNAP ]
|
||||||
|
then
|
||||||
|
echo "Deleting old ZFS snapshot $LASTSNAP"
|
||||||
|
zfs destroy "$SRCZFS"@"$LASTSNAP"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
abortFunction
|
abortFunction
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user