1
0

control ZFS pool with ZPOOL envvar; simplify code

This commit is contained in:
michele
2014-03-20 13:45:16 +01:00
parent 60edb5e5ab
commit 418f021c23
2 changed files with 44 additions and 52 deletions

View File

@ -1,11 +1,13 @@
#! /bin/sh
# change this to the name of your ZFS pool.
zpool="zroot"
# change this to the name of your ZFS pool. Or set ZPOOL envvar at runtime
zpool=${ZPOOL:-"zroot"}
# name of backup to take
bkname=${1:-"default"}
# make a backup collection having 1 full and N-1 incremental backups.
# set to 1 to avoid incrementals and always take full dumps.
max_incremental=4
max_incremental=${2:-"4"}
usage () {
echo "Usage:"
@ -18,23 +20,21 @@ usage () {
echo "UPLOAD_PATH upload generated backup to this path. scp:// or rsync://"
}
# first argument: name of backup set
if [ $# -lt 1 ]
then
failmsg () {
echo $*
echo
usage
exit 1
fi
}
bkname=$1
if ! echo $bkname | grep -qiE '^[a-z0-9-]+$'
then
echo "Given bkname is invalid. Want alphanumeric and hyphens."
exit 1
fi
if echo "$2" | grep -qE '^[1-9][0-9]*$'
then
max_incremental=$2
fi
verify_zpool () {
zpool status $zpool >/dev/null 2>&1 || failmsg "ZFS pool '$zpool' not found. Fix your \$ZPOOL envvar."
}
verify_zpool
echo $bkname | grep -qiE '^[a-z0-9]+$' || failmsg "Given bkname is invalid. Want alphanumeric."
echo "$max_incremental" | grep -qE '^[1-9][0-9]*$' || failmsg "Invalid number of backups sequence steps, want positive integer."
export PATH=$PATH:/usr/local/bin