summaryrefslogtreecommitdiff
path: root/ezjail-admin
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2013-05-10 19:12:50 +0000
committererdgeist <erdgeist@erdgeist.org>2013-05-10 19:12:50 +0000
commit721ae5e99d0312568af825ba6734d5dc84c7b85f (patch)
tree500fd7de39e43ed09a60df671b4728641a498dd2 /ezjail-admin
parent84db3c9c8a387ed9132b00500c3fd8386851ad40 (diff)
change retention policy so that per window the oldest and the newest snapshot is kept, unless the newer one is not new enough ;)
Diffstat (limited to 'ezjail-admin')
-rwxr-xr-xezjail-admin21
1 files changed, 16 insertions, 5 deletions
diff --git a/ezjail-admin b/ezjail-admin
index 0f7dd1e..7867c6c 100755
--- a/ezjail-admin
+++ b/ezjail-admin
@@ -446,7 +446,7 @@ ensure_jailzfs() {
446 446
447# implement snapshot retentions 447# implement snapshot retentions
448filteroldsnapshots() { 448filteroldsnapshots() {
449 local win repeat bottom in_window snap_id snap_del first_round_done max_diff 449 local win repeat bottom in_window snap_id snap_del snap_first first_round_done max_diff
450 bottom=`date +%s` 450 bottom=`date +%s`
451 451
452 unset snap_del first_round_done 452 unset snap_del first_round_done
@@ -461,12 +461,12 @@ filteroldsnapshots() {
461 # values default to minutes 461 # values default to minutes
462 case ${win} in *h) m=60;; *d) m=1440;; *w) m=10080;; *y) m=*525600;; *) m=1;; esac 462 case ${win} in *h) m=60;; *d) m=1440;; *w) m=10080;; *y) m=*525600;; *) m=1;; esac
463 win=$((${win%[mhdwy]}*m*60)) 463 win=$((${win%[mhdwy]}*m*60))
464 max_diff=$(( 3 * win / 4 ))
465 464
466 # innerloop $repeats over windows 465 # innerloop $repeats over windows
467 while [ $(( repeat-=1 )) -ge 0 ]; do 466 while [ $(( repeat-=1 )) -ge 0 ]; do
468 # Shift bottom of window 467 # Shift bottom of window
469 bottom=$(( ${bottom} - ${win} )) 468 bottom=$(( ${bottom} - ${win} ))
469 unset snap_first
470 470
471 # now loop over parameters 471 # now loop over parameters
472 in_window=YES; while [ "${in_window}" ]; do 472 in_window=YES; while [ "${in_window}" ]; do
@@ -482,14 +482,25 @@ filteroldsnapshots() {
482 [ "${first_round_done}" ] || echo /sbin/zfs snapshot -r ${ezjail_zfs}@ez-autosnap-`date +${ezjail_snap_date_format}` 482 [ "${first_round_done}" ] || echo /sbin/zfs snapshot -r ${ezjail_zfs}@ez-autosnap-`date +${ezjail_snap_date_format}`
483 [ "${first_round_done}" ] || /sbin/zfs snapshot -r ${ezjail_zfs}@ez-autosnap-`date +${ezjail_snap_date_format}` 483 [ "${first_round_done}" ] || /sbin/zfs snapshot -r ${ezjail_zfs}@ez-autosnap-`date +${ezjail_snap_date_format}`
484 484
485 # we remembered the first snapshot in window
486 # only keep it, if it is newer than the oldest by more than half the window size
487 if [ "${snap_first}" -a "${snap_del}" -a $(( snap_del - snap_first )) -lt $(( win / 2 )) ]; then
488 echo /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_first} +${ezjail_snap_date_format}`
489 /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_first} +${ezjail_snap_date_format}`
490 fi
491
485 # Zero marks end of snaps list 492 # Zero marks end of snaps list
486 [ "${snap_id}" -eq 0 ] && return 493 [ "${snap_id}" -eq 0 ] && return
487 494
488 unset snap_del in_window 495 unset snap_del in_window
489 else 496 else
490 if [ "${snap_del}" -a $(( snap_del - snap_id )) -lt ${max_diff} ]; then 497 if [ "${snap_del}" ]; then
491 echo /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_del} +${ezjail_snap_date_format}` 498 if [ "${snap_first}" ]; then
492 /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_del} +${ezjail_snap_date_format}` 499 echo /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_del} +${ezjail_snap_date_format}`
500 /sbin/zfs destroy -r ${ezjail_zfs}@ez-autosnap-`date -j -f %s ${snap_del} +${ezjail_snap_date_format}`
501 else
502 snap_first="${snap_del}"
503 fi
493 fi 504 fi
494 snap_del="${snap_id}" 505 snap_del="${snap_id}"
495 snap_id=0 506 snap_id=0