cleanup: support maximum age of backups
This commit is contained in:
parent
eaf2cc11c3
commit
5d8ec2140c
18
zb-cleanup
18
zb-cleanup
|
@ -1,12 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if [[ -z "$1" || -z "$2" ]] ; then
|
if [[ -z "$1" || -z "$2" ]] ; then
|
||||||
echo "usage: $0 <zfs_object> <density_percent>" >&2
|
echo "usage: $0 <zfs_object> <density_percent> [max_age]" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$2" -lt 100 ]] ; then
|
if [[ "$2" -lt 100 ]] ; then
|
||||||
echo "density must not be lower than 100" >&2
|
echo "density must be >= 100" >&2
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -17,6 +17,11 @@ timestamp () {
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
max_age=0
|
||||||
|
if [[ -n "$3" ]] ; then
|
||||||
|
max_age=`date --date="$3" +%s`
|
||||||
|
fi
|
||||||
|
|
||||||
density="$2"
|
density="$2"
|
||||||
timenow=`date +%s`
|
timenow=`date +%s`
|
||||||
lasttime=0
|
lasttime=0
|
||||||
|
@ -30,12 +35,19 @@ done |sort -n | while read l ; do
|
||||||
curtime=${l%% *}
|
curtime=${l%% *}
|
||||||
snapname=${l#* }
|
snapname=${l#* }
|
||||||
|
|
||||||
|
if [ "$curtime" -lt "$max_age" ] ; then
|
||||||
|
#too old
|
||||||
|
zfs destroy "$snapname"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$curtime" -ge "$timenow" ] ; then
|
if [ "$curtime" -ge "$timenow" ] ; then
|
||||||
|
#this actually shouldn't happen, but who knows
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#if it's too dense, delete the closer snapshot
|
#if it's too dense, delete the closer snapshot
|
||||||
if [ $(( $density*($curtime-$lasttime)/($timenow-$lasttime) )) -lt 100 ]
|
if [ $(( ($density*($curtime-$lasttime))/($timenow-$lasttime) )) -lt 100 ]
|
||||||
then
|
then
|
||||||
zfs destroy "$snapname"
|
zfs destroy "$snapname"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue