From 721ae5e99d0312568af825ba6734d5dc84c7b85f Mon Sep 17 00:00:00 2001 From: erdgeist Date: Fri, 10 May 2013 19:12:50 +0000 Subject: change retention policy so that per window the oldest and the newest snapshot is kept, unless the newer one is not new enough ;) --- ezjail-admin | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'ezjail-admin') diff --git a/ezjail-admin b/ezjail-admin index 0f7dd1e..7867c6c 100755 --- a/ezjail-admin +++ b/ezjail-admin @@ -446,7 +446,7 @@ ensure_jailzfs() { # implement snapshot retentions filteroldsnapshots() { - local win repeat bottom in_window snap_id snap_del first_round_done max_diff + local win repeat bottom in_window snap_id snap_del snap_first first_round_done max_diff bottom=`date +%s` unset snap_del first_round_done @@ -461,12 +461,12 @@ filteroldsnapshots() { # values default to minutes case ${win} in *h) m=60;; *d) m=1440;; *w) m=10080;; *y) m=*525600;; *) m=1;; esac win=$((${win%[mhdwy]}*m*60)) - max_diff=$(( 3 * win / 4 )) # innerloop $repeats over windows while [ $(( repeat-=1 )) -ge 0 ]; do # Shift bottom of window bottom=$(( ${bottom} - ${win} )) + unset snap_first # now loop over parameters in_window=YES; while [ "${in_window}" ]; do @@ -482,14 +482,25 @@ filteroldsnapshots() { [ "${first_round_done}" ] || echo /sbin/zfs snapshot -r ${ezjail_zfs}@ez-autosnap-`date +${ezjail_snap_date_format}` [ "${first_round_done}" ] || /sbin/zfs snapshot -r ${ezjail_zfs}@ez-autosnap-`date +${ezjail_snap_date_format}` + # we remembered the first snapshot in window + # only keep it, if it is newer than the oldest by more than half the window size + if [ "${snap_first}" -a "${snap_del}" -a $(( snap_del - snap_first )) -lt $(( win / 2 )) ]; then + echo /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_first} +${ezjail_snap_date_format}` + /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_first} +${ezjail_snap_date_format}` + fi + # Zero marks end of snaps list [ "${snap_id}" -eq 0 ] && return unset snap_del in_window else - if [ "${snap_del}" -a $(( snap_del - snap_id )) -lt ${max_diff} ]; then - echo /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_del} +${ezjail_snap_date_format}` - /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_del} +${ezjail_snap_date_format}` + if [ "${snap_del}" ]; then + if [ "${snap_first}" ]; then + echo /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_del} +${ezjail_snap_date_format}` + /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_del} +${ezjail_snap_date_format}` + else + snap_first="${snap_del}" + fi fi snap_del="${snap_id}" snap_id=0 -- cgit v1.2.3