Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/zfs-auto-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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=''
Expand Down Expand Up @@ -629,3 +648,4 @@ print_log notice "@$SNAPNAME," \

exit 0
# }