Added --min-size

Added an option to inhibit generation of empty (or very small) snapshots.
This commit is contained in:
rkarlsba 2017-01-16 00:59:13 +01:00 committed by GitHub
parent d5cb31aaae
commit 27413ac798

View File

@ -42,6 +42,7 @@ opt_verbose=''
opt_pre_snapshot=''
opt_post_snapshot=''
opt_do_snapshots=1
opt_min_size=0
# Global summary statistics.
DESTRUCTION_COUNT='0'
@ -161,7 +162,23 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
for ii in $TARGETS
do
if [ -n "$opt_do_snapshots" ]
# Check if size check is > 0
size_check_skip=0
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
size_check_skip=1
if [ $opt_verbose -gt 0 ]
then
echo "Skipping target $ii, only $kb_written kB written since last snap. opt_min_size is $opt_min_size"
fi
fi
fi
if [ -n "$opt_do_snapshots" -a "$size_check_skip" -eq 0 ]
then
if [ "$opt_pre_snapshot" != "" ]
then
@ -212,7 +229,8 @@ GETOPT=$(getopt \
--longoptions=event:,keep:,label:,prefix:,sep: \
--longoptions=debug,help,quiet,syslog,verbose \
--longoptions=pre-snapshot:,post-snapshot:,destroy-only \
--options=dnshe:l:k:p:rs:qgv \
--longoptions=min-size: \
--options=dnshe:l:k:p:rs:qgvm: \
-- "$@" ) \
|| exit 128
@ -271,6 +289,10 @@ do
opt_label="$2"
shift 2
;;
(-m|--min-size)
opt_min_size="$2"
shift 2
;;
(-p|--prefix)
opt_prefix="$2"
while test "${#opt_prefix}" -gt '0'