added threshold
This commit is contained in:
@@ -26,3 +26,8 @@ make uninstall
|
||||
# NOTE #
|
||||
uninstalling the script doesn't delete made snapshots
|
||||
|
||||
in src folder, before installing, you can customize some parameters
|
||||
--keep indicates the number of snapshots to save. Default to 10
|
||||
--label indicates the label of snapshots. Default to defaultLabel
|
||||
--threshold indicates how many bytes need to be written in a dataset after the last snapshot to allow new snapshots. Default 0
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
opt_prefix='zfs-auto-snap'
|
||||
opt_keep=10
|
||||
opt_label="defaultLabel"
|
||||
opt_threshold=0
|
||||
|
||||
do_snapshots ()
|
||||
{
|
||||
@@ -8,10 +11,21 @@ do_snapshots ()
|
||||
|
||||
for ii in $TARGETS
|
||||
do
|
||||
zfs snapshot "$ii@$SNAPNAME"
|
||||
|
||||
KEEP="$opt_keep"
|
||||
|
||||
if [ "$opt_threshold" -eq 0 ]
|
||||
then
|
||||
zfs snapshot "$ii@$SNAPNAME"
|
||||
else
|
||||
bytes_written=`zfs get -Hp -o value written $ii`
|
||||
if [ "$bytes_written" -ge "$opt_threshold" ]
|
||||
then
|
||||
zfs snapshot "$ii@$SNAPNAME"
|
||||
else
|
||||
KEEP=$(( $KEEP + 1 ))
|
||||
fi
|
||||
fi
|
||||
|
||||
# ASSERT: The old snapshot list is sorted by increasing age.
|
||||
for jj in $SNAPSHOTS_OLD
|
||||
do
|
||||
@@ -33,12 +47,14 @@ do_snapshots ()
|
||||
# main ()
|
||||
# {
|
||||
|
||||
|
||||
while [ "$#" -gt '0' ]
|
||||
do
|
||||
case "$1" in
|
||||
--keep)
|
||||
if [ ! "$2" -gt '0' ];
|
||||
then
|
||||
echo "keep parameters need to be greater than 0"
|
||||
exit 1
|
||||
fi
|
||||
opt_keep="$2"
|
||||
@@ -48,6 +64,15 @@ do
|
||||
opt_label="$2"
|
||||
shift 2
|
||||
;;
|
||||
--threshold)
|
||||
if [ ! "$2" -ge '0' ];
|
||||
then
|
||||
echo "threshold parameters need to be equal or greater than 0"
|
||||
exit 1
|
||||
fi
|
||||
opt_threshold="$2"
|
||||
shift 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
Reference in New Issue
Block a user