add backup:days as zfs value

This commit is contained in:
Jochen Welzel 2021-01-07 13:10:30 +01:00
parent b4b0b16282
commit 4e4358e517

View File

@ -31,8 +31,15 @@ then
helpFunction
fi
DAYS=$(zfs get backup:days -H -o value $SRCZFS)
if [[ $DAYS == "-" ]]
then
DAYS=7
fi
DAYS=$(($DAYS + 1))
DATE=$(date "+%Y%m%d%H%M")
DATE30=$(date -d "-30day" "+%Y%m%d")
DATEOLD=$(date -d -"$DAYS"day "+%Y%m%d")
SNAPNAME="backup_$DATE"
echo "$(date +%Y-%m-%d_%H:%M:%S): Starting Backup of $VM"
@ -133,7 +140,7 @@ zfs destroy tank/snapshots/$VM
# cleanup old backups
OLDSNAPS=$(ssh $DESTHOST zfs list -r -t snapshot -o name $DESTZFS 2>/dev/null | grep $DATE30)
OLDSNAPS=$(ssh $DESTHOST zfs list -r -t snapshot -o name $DESTZFS 2>/dev/null | grep $DATEOLD)
if [ ${#OLDSNAPS} -gt 0 ]
then
for oldsnap in $OLDSNAPS
@ -142,7 +149,7 @@ then
ssh $DESTHOST sudo zfs destroy $oldsnap
done
else
echo "No old snapshots to cleanup"
echo "$(date +%Y-%m-%d_%H:%M:%S): No old snapshots to cleanup on target"
fi
echo "$(date +%Y-%m-%d_%H:%M:%S): Backup Completed"