add old snapshot deletion
This commit is contained in:
parent
7fb8538a44
commit
44dc136c8a
@ -35,6 +35,13 @@ 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"
|
||||||
|
|
||||||
|
abortFunction()
|
||||||
|
{
|
||||||
|
zfs set backup:success="false" $SRCZFS
|
||||||
|
zfs set backup:failed="$DATE" $SRCZFS
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
VMDISKS=$(virsh domblklist $VM | egrep -o vd.)
|
VMDISKS=$(virsh domblklist $VM | egrep -o vd.)
|
||||||
DISKSPEC=""
|
DISKSPEC=""
|
||||||
for disk in $VMDISKS
|
for disk in $VMDISKS
|
||||||
@ -55,7 +62,7 @@ then
|
|||||||
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
echo "VM snapshot creation failed" >&2
|
echo "VM snapshot creation failed" >&2
|
||||||
exit 1
|
abortFunction
|
||||||
else
|
else
|
||||||
echo "Snapshot created without --quiesce"
|
echo "Snapshot created without --quiesce"
|
||||||
fi
|
fi
|
||||||
@ -65,7 +72,7 @@ zfs snapshot "$SRCZFS"@"$SNAPNAME"
|
|||||||
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
echo "ZFS snapshot creation failed" >&2
|
echo "ZFS snapshot creation failed" >&2
|
||||||
exit 1
|
abortFunction
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for disk in $VMDISKS
|
for disk in $VMDISKS
|
||||||
@ -79,7 +86,7 @@ do
|
|||||||
if [[ $disk == *"snapshot"* ]]
|
if [[ $disk == *"snapshot"* ]]
|
||||||
then
|
then
|
||||||
echo "Snapshot deletion failed for $disk" >&2
|
echo "Snapshot deletion failed for $disk" >&2
|
||||||
exit 1
|
abortFunction
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -102,9 +109,20 @@ then
|
|||||||
zfs set backup:date="$DATE" $SRCZFS
|
zfs set backup:date="$DATE" $SRCZFS
|
||||||
zfs destroy "$SRCZFS"@"$LASTSNAP"
|
zfs destroy "$SRCZFS"@"$LASTSNAP"
|
||||||
else
|
else
|
||||||
zfs set backup:success="false" $SRCZFS
|
abortFunction
|
||||||
zfs set backup:failed="$DATE" $SRCZFS
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
zfs destroy tank/snapshots/$VM
|
zfs destroy tank/snapshots/$VM
|
||||||
|
|
||||||
|
# cleanup old backups
|
||||||
|
|
||||||
|
OLDSNAPS=$(ssh $DESTHOST zfs list -r -t snapshot -o name $DESTZFS 2>/dev/null | grep $DATE30)
|
||||||
|
if [ ${#OLDSNAPS} -gt 0 ]
|
||||||
|
then
|
||||||
|
for oldsnap in $OLDSNAPS
|
||||||
|
do
|
||||||
|
ssh $DESTHOST sudo zfs destroy $oldsnap
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "No old snapshots to cleanup"
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user