Skip to content

Commit 897ca02

Browse files
author
Jonathan Carter
authored
Merge pull request #59 from rkarlsba/patch-3
Added --min-size
2 parents 3e48c89 + 27413ac commit 897ca02

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/zfs-auto-snapshot.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ opt_verbose=''
4242
opt_pre_snapshot=''
4343
opt_post_snapshot=''
4444
opt_do_snapshots=1
45+
opt_min_size=0
4546

4647
# Global summary statistics.
4748
DESTRUCTION_COUNT='0'
@@ -161,7 +162,23 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
161162

162163
for ii in $TARGETS
163164
do
164-
if [ -n "$opt_do_snapshots" ]
165+
# Check if size check is > 0
166+
size_check_skip=0
167+
if [ "$opt_min_size" -gt 0 ]
168+
then
169+
bytes_written=`zfs get -Hp -o value written $ii`
170+
kb_written=$(( $bytes_written / 1024 ))
171+
if [ "$kb_written" -lt "$opt_min_size" ]
172+
then
173+
size_check_skip=1
174+
if [ $opt_verbose -gt 0 ]
175+
then
176+
echo "Skipping target $ii, only $kb_written kB written since last snap. opt_min_size is $opt_min_size"
177+
fi
178+
fi
179+
fi
180+
181+
if [ -n "$opt_do_snapshots" -a "$size_check_skip" -eq 0 ]
165182
then
166183
if [ "$opt_pre_snapshot" != "" ]
167184
then
@@ -212,7 +229,8 @@ GETOPT=$(getopt \
212229
--longoptions=event:,keep:,label:,prefix:,sep: \
213230
--longoptions=debug,help,quiet,syslog,verbose \
214231
--longoptions=pre-snapshot:,post-snapshot:,destroy-only \
215-
--options=dnshe:l:k:p:rs:qgv \
232+
--longoptions=min-size: \
233+
--options=dnshe:l:k:p:rs:qgvm: \
216234
-- "$@" ) \
217235
|| exit 128
218236

@@ -271,6 +289,10 @@ do
271289
opt_label="$2"
272290
shift 2
273291
;;
292+
(-m|--min-size)
293+
opt_min_size="$2"
294+
shift 2
295+
;;
274296
(-p|--prefix)
275297
opt_prefix="$2"
276298
while test "${#opt_prefix}" -gt '0'

0 commit comments

Comments
 (0)