added threshold
This commit is contained in:
@@ -26,3 +26,8 @@ make uninstall
|
|||||||
# NOTE #
|
# NOTE #
|
||||||
uninstalling the script doesn't delete made snapshots
|
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
|
#!/bin/sh
|
||||||
|
|
||||||
opt_prefix='zfs-auto-snap'
|
opt_prefix='zfs-auto-snap'
|
||||||
|
opt_keep=10
|
||||||
|
opt_label="defaultLabel"
|
||||||
|
opt_threshold=0
|
||||||
|
|
||||||
do_snapshots ()
|
do_snapshots ()
|
||||||
{
|
{
|
||||||
@@ -8,10 +11,21 @@ do_snapshots ()
|
|||||||
|
|
||||||
for ii in $TARGETS
|
for ii in $TARGETS
|
||||||
do
|
do
|
||||||
zfs snapshot "$ii@$SNAPNAME"
|
|
||||||
|
|
||||||
KEEP="$opt_keep"
|
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.
|
# ASSERT: The old snapshot list is sorted by increasing age.
|
||||||
for jj in $SNAPSHOTS_OLD
|
for jj in $SNAPSHOTS_OLD
|
||||||
do
|
do
|
||||||
@@ -33,12 +47,14 @@ do_snapshots ()
|
|||||||
# main ()
|
# main ()
|
||||||
# {
|
# {
|
||||||
|
|
||||||
|
|
||||||
while [ "$#" -gt '0' ]
|
while [ "$#" -gt '0' ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--keep)
|
--keep)
|
||||||
if [ ! "$2" -gt '0' ];
|
if [ ! "$2" -gt '0' ];
|
||||||
then
|
then
|
||||||
|
echo "keep parameters need to be greater than 0"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
opt_keep="$2"
|
opt_keep="$2"
|
||||||
@@ -48,6 +64,15 @@ do
|
|||||||
opt_label="$2"
|
opt_label="$2"
|
||||||
shift 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
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user