aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2014-06-07 11:39:13 +0200
committerMirek Kratochvil <exa.exa@gmail.com>2014-06-07 11:39:13 +0200
commit5d8ec2140c95623ce2b620eab1519aa0e141b448 (patch)
treeca6db18d4e2c978fbdc1c587156a92dd7f983478
parenteaf2cc11c3dd21fdf2263ee0807de7ce1c8d2871 (diff)
downloadzfs-backup-5d8ec2140c95623ce2b620eab1519aa0e141b448.tar.gz
zfs-backup-5d8ec2140c95623ce2b620eab1519aa0e141b448.tar.bz2
cleanup: support maximum age of backups
-rwxr-xr-xzb-cleanup18
1 files changed, 15 insertions, 3 deletions
diff --git a/zb-cleanup b/zb-cleanup
index fbefd4d..9761ebf 100755
--- a/zb-cleanup
+++ b/zb-cleanup
@@ -1,12 +1,12 @@
#!/bin/bash
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
fi
if [[ "$2" -lt 100 ]] ; then
- echo "density must not be lower than 100" >&2
+ echo "density must be >= 100" >&2
exit 2
fi
@@ -17,6 +17,11 @@ timestamp () {
return $?
}
+max_age=0
+if [[ -n "$3" ]] ; then
+ max_age=`date --date="$3" +%s`
+fi
+
density="$2"
timenow=`date +%s`
lasttime=0
@@ -30,12 +35,19 @@ done |sort -n | while read l ; do
curtime=${l%% *}
snapname=${l#* }
+ if [ "$curtime" -lt "$max_age" ] ; then
+ #too old
+ zfs destroy "$snapname"
+ continue
+ fi
+
if [ "$curtime" -ge "$timenow" ] ; then
+ #this actually shouldn't happen, but who knows
break
fi
#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
zfs destroy "$snapname"
else