diff --git a/src/zfs-auto-snapshot.sh b/src/zfs-auto-snapshot.sh index cd88f0f..f223286 100644 --- a/src/zfs-auto-snapshot.sh +++ b/src/zfs-auto-snapshot.sh @@ -43,6 +43,7 @@ opt_pre_snapshot='' opt_post_snapshot='' opt_do_snapshots=1 opt_min_size=0 +opt_changed=0 # Global summary statistics. DESTRUCTION_COUNT='0' @@ -57,6 +58,7 @@ print_usage () { echo "Usage: $0 [options] [-l label] <'//' | name [name...]> --default-exclude Exclude datasets if com.sun:auto-snapshot is unset. + -c, --changed Snap only if data written > 0. -d, --debug Print debugging messages. -e, --event=EVENT Set the com.sun:auto-snapshot-desc property to EVENT. --fast Use a faster zfs list invocation. @@ -164,9 +166,9 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...] do # Check if size check is > 0 size_check_skip=0 + bytes_written=`zfs get -Hp -o value written $ii` if [ "$opt_min_size" -gt 0 ] then - bytes_written=`zfs get -Hp -o value written $ii` kb_written=$(( $bytes_written / 1024 )) if [ "$kb_written" -lt "$opt_min_size" ] then @@ -176,7 +178,20 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...] echo "Skipping target $ii, only $kb_written kB written since last snap. opt_min_size is $opt_min_size" fi fi - fi + fi + + # Force check if data changed + if [ "$opt_changed" -eq 1 ] + then + if [ "$bytes_written" -eq 0 ] + then + size_check_skip=1 + if [ $opt_verbose -gt 0 ] + then + echo "Skipping target $ii, 0 bytes written since last snap." + fi + fi + fi if [ -n "$opt_do_snapshots" -a "$size_check_skip" -eq 0 ] then @@ -245,6 +260,10 @@ eval set -- "$GETOPT" while [ "$#" -gt '0' ] do case "$1" in + (-c|--changed) + opt_changed=1 + shift 1 + ;; (-d|--debug) opt_debug='1' opt_quiet='' @@ -629,3 +648,4 @@ print_log notice "@$SNAPNAME," \ exit 0 # } +