aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2014-04-08 19:38:36 +0200
committerMirek Kratochvil <exa.exa@gmail.com>2014-04-08 19:38:36 +0200
commitd55edaf2a78c8f7d63d120cc616686b65983c31c (patch)
tree21fd3e9dbc8fbb943a4ae420999221d73b4cedad
parentfabd07c68a40ac52993f2889f1f8f3b164563253 (diff)
downloadzfs-backup-d55edaf2a78c8f7d63d120cc616686b65983c31c.tar.gz
zfs-backup-d55edaf2a78c8f7d63d120cc616686b65983c31c.tar.bz2
zb-cleanup implemented
-rwxr-xr-xzb-cleanup32
1 files changed, 31 insertions, 1 deletions
diff --git a/zb-cleanup b/zb-cleanup
index 13f4793..cadb717 100755
--- a/zb-cleanup
+++ b/zb-cleanup
@@ -1,2 +1,32 @@
-#!/bin/sh
+#!/bin/bash
+if [[ -z "$1" || -z "$2" ]] ; then
+ echo "usage: $0 <volume> <density>" >&2
+ exit 1
+fi
+
+timestamp () {
+ t="`echo \"$1\" |sed -e 's/^.*@zb-//' |tr 'p_' '+ '`"
+ date --date="$t" +%s
+}
+
+density="$2"
+timenow=`date +%s`
+lasttime=0
+
+zfs list -t snapshot -r -d 1 -H "$1" |awk '{print $1;}' | while read l ; do
+ echo `timestamp "$l"` "$l"
+done |sort -n | while read l ; do
+ curtime=${l%% *}
+ snapname=${l#* }
+
+ if [ "$curtime" -ge "$timenow" ] ; then
+ break
+ fi
+
+ if [ `echo "$density*($curtime-$lasttime)/($timenow-$lasttime)"` -lt 1] ; then
+ zfs destroy "$snapname"
+ else
+ lasttime="$curtime"
+ fi
+done