snap-sync: new cmdline-option 'backupdir'

- predefine a backupdir. This path is relative to the backup_root.
  It will be created as a subdirectory on target disk if necessary.
- parse_params(): accept lowercase option --target, --uuid

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2017-11-21 18:35:14 +01:00
parent c36d92159e
commit cd60b4d022

View File

@@ -183,6 +183,10 @@ parse_params () {
# Call usage() function. # Call usage() function.
usage usage
;; ;;
-b|--backupdir)
backupdir_cmdline="$2"
shift 2
;;
-c|--config) -c|--config)
selected_config="$2" selected_config="$2"
shift 2 shift 2
@@ -200,11 +204,11 @@ parse_params () {
subvolid_cmdline="$2" subvolid_cmdline="$2"
shift 2 shift 2
;; ;;
-t|--TARGET) -t|--target|--TARGET)
target_cmdline="$2" target_cmdline="$2"
shift 2 shift 2
;; ;;
-u|--UUID) -u|--uuid|--UUID)
uuid_cmdline="$2" uuid_cmdline="$2"
shift 2 shift 2
;; ;;
@@ -212,6 +216,10 @@ parse_params () {
verbose=1 verbose=1
shift 1 shift 1
;; ;;
--backupdir=*)
backupdir_cmdline=${1#*=}
shift
;;
--config=*) --config=*)
selected_config=${1#*=} selected_config=${1#*=}
shift shift
@@ -229,11 +237,11 @@ parse_params () {
subvolid_cmdline=${1#*=} subvolid_cmdline=${1#*=}
shift shift
;; ;;
--TARGET=*) --target=*|TARGET=*)
target_cmdline=${1#*=} target_cmdline=${1#*=}
shift shift
;; ;;
--UUID=*) --uuid=*|UUID=*)
uuid_cmdline=${1#*=} uuid_cmdline=${1#*=}
shift shift
;; ;;
@@ -260,6 +268,7 @@ parse_params () {
uuid_cmdline=${uuid_cmdline:-"none"} uuid_cmdline=${uuid_cmdline:-"none"}
target_cmdline=${target_cmdline:-"none"} target_cmdline=${target_cmdline:-"none"}
subvolid_cmdline=${subvolid_cmdline:-"none"} subvolid_cmdline=${subvolid_cmdline:-"none"}
backupdir_cmdline=${backupdir_cmdline:-"none"}
if [ -z $remote ]; then if [ -z $remote ]; then
ssh="" ssh=""
@@ -367,20 +376,21 @@ run_config () {
eval "snapper_sync_id_$i='$snapper_sync_id'" eval "snapper_sync_id_$i='$snapper_sync_id'"
eval "snapper_sync_snapshot_$i='$snapper_sync_snapshot'" eval "snapper_sync_snapshot_$i='$snapper_sync_snapshot'"
# verify backupdir
if [ -z "$snapper_sync_id" ]; then if [ -z "$snapper_sync_id" ]; then
printf "No backups have been performed for snapper config '%s' on target disk.\n" "$selected_config" printf "No backups have been performed for snapper config '%s' on target disk.\n" "$selected_config"
if [ $noconfirm ]; then if [ "$backupdir_cmdline" != "none" ]; then
# go with defaults backupdir=$backupdir_cmdline
if [ "$verbose" ]; then
printf "using defaults\n"
fi
else
read -r -p "Enter name of directory to store backups, relative to $selected_target (to be created if not existing): " backupdir
fi
if [ -z "$backupdir" ]; then
backup_root="$selected_target"
else
backup_root="$selected_target/$backupdir" backup_root="$selected_target/$backupdir"
else
if [ ! $noconfirm ]; then
read -r -p "Enter name of directory to store backups, relative to $selected_target (to be created if not existing): " backupdir
if [ -z "$backupdir" ]; then
backup_root="$selected_target"
else
backup_root="$selected_target/$backupdir"
fi
fi
fi fi
else else
if [ "$verbose" ]; then if [ "$verbose" ]; then