snap-sync: improve parse_params()

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2017-11-24 13:51:51 +01:00
parent 8a57d7807d
commit ae000058ac

View File

@@ -273,17 +273,39 @@ parse_params () {
fi fi
shift 2 shift 2
;; ;;
-d|--description|--description-finished) --description-finished)
description="$2" shift
shift 2 snap_description_finished="${*}"
snap_description_finished="${snap_description_finished%% -*}"
params=$*
set -- $snap_description_finished
count=$#
set -- $params
shift $count
;; ;;
--description-running) --description-running)
description="$2" shift
shift 2 snap_description_running=${*}
snap_description_running="${snap_description_running%% -*}"
params=$*
set -- $snap_description_running
count=$#
set -- $params
shift $count
;; ;;
--description-synced) -d|--description|--description-synced)
description="$2" shift
shift 2 snap_description_synced="${*}"
snap_description_synced="${snap_description_synced%% -*}"
params=$*
set -- $snap_description_synced
count=$#
set -- $params
shift $count
;;
--dry-run)
dryrun=1
shift 1
;; ;;
-i|--interactive) -i|--interactive)
interactive=1 interactive=1
@@ -295,6 +317,10 @@ parse_params () {
donotify=0 donotify=0
shift shift
;; ;;
--remote)
remote=$2
shift 2
;;
-s|--subvolid|--SUBVOLID) -s|--subvolid|--SUBVOLID)
subvolid_cmdline="$2" subvolid_cmdline="$2"
shift 2 shift 2
@@ -311,6 +337,10 @@ parse_params () {
verbose=1 verbose=1
shift 1 shift 1
;; ;;
--version)
printf "%s v%s\n" "$progname" "$version"
exit 0
;;
--backupdir=*) --backupdir=*)
backupdir_cmdline=${1#*=} backupdir_cmdline=${1#*=}
shift shift
@@ -323,13 +353,41 @@ parse_params () {
fi fi
shift shift
;; ;;
--dry-run) --description-finished=*)
dryrun=1 snap_description_finished="${*#*=}"
shift 1 snap_description_finished="${snap_description_finished%% -*}"
params_new=${*#*=}
params_new=${params_new##${snap_description_finished}}
if [ ${#params_new} -gt 0 ]; then
set -- $snap_description_finished
count=$#
set -- $params_new
fi
;; ;;
--remote) --description-running=*)
remote=$2 snap_description_running="${*#*=}"
shift 2 snap_description_running="${snap_description_running%% -*}"
params_new=${*#*=}
params_new=${params_new##${snap_description_running}}
params=$#
if [ ${#params_new} -gt 0 ]; then
set -- $snap_description_running
count=$#
set -- $params_new
fi
;;
-d=*|--description=*|--description-synced=*)
snap_description_synced="${*#*=}"
snap_description_synced="${snap_description_synced%% -*}"
params_new=${*#*=}
params_new=${params_new##${snap_description_synced}}
if [ ${#params_new} -gt 0 ]; then
set -- $snap_description_synced
count=$#
set -- $params_new
else
break
fi
;; ;;
--remote=*) --remote=*)
remote=${1#*=} remote=${1#*=}
@@ -366,9 +424,9 @@ parse_params () {
. $SNAPPER_CONFIG . $SNAPPER_CONFIG
selected_configs=${selected_configs:-$SNAPPER_CONFIGS} selected_configs=${selected_configs:-$SNAPPER_CONFIGS}
snap_description_synced=${description_lastsync:-"snap-sync last incremental"} snap_description_finished=${snap_description_finished:-"snap-sync backup"}
snap_description_finished=${description_finished:-"snap-sync backup"} snap_description_running=${snap_description_running:-"snap-sync in progress"}
snap_description_running=${description_running:-"snap-sync in progress"} snap_description_synced=${snap_description_synced:-"snap-sync last incremental"}
uuid_cmdline=${uuid_cmdline:-"none"} uuid_cmdline=${uuid_cmdline:-"none"}
target_cmdline=${target_cmdline:-"none"} target_cmdline=${target_cmdline:-"none"}
@@ -394,8 +452,8 @@ parse_params () {
printf "Snapper Descriptions\n" printf "Snapper Descriptions\n"
printf " backup finished: '%s'\n" "$snap_description_finished" printf " backup finished: '%s'\n" "$snap_description_finished"
printf " backup synced: '%s'\n" "$snap_description_synced"
printf " backup running: '%s'\n" "$snap_description_running" printf " backup running: '%s'\n" "$snap_description_running"
printf " backup synced: '%s'\n" "$snap_description_synced"
if [ "$verbose" ]; then snap_sync_options="verbose=true"; fi if [ "$verbose" ]; then snap_sync_options="verbose=true"; fi
if [ "$dryrun" ]; then snap_sync_options="${snap_sync_options} dry-run=true"; fi if [ "$dryrun" ]; then snap_sync_options="${snap_sync_options} dry-run=true"; fi
@@ -965,22 +1023,26 @@ $progname $version
Usage: $progname [options] Usage: $progname [options]
Options: Options:
-d, --description <desc> Change the snapper description. Default: "latest incremental backup" -d, --description <desc> Change the snapper description. Default: "latest incremental backup"
-c, --config <config> Specify the snapper configuration to use. Otherwise will perform for each snapper --label-finished <desc> snapper description tagging successful jobs. Default: "snap-sync backup"
configuration. Can list multiple configurations within quotes, space-separated --label-running <desc> snapper description tagging active jobs. Default: "snap-sync in progress"
(e.g. -c "root home"). --label-synced <desc> snapper description tagging last synced jobs.
-n, --noconfirm Do not ask for confirmation for each configuration. Will still prompt for backup Default: "snap-sync last incremental"
--batch directory name on first backup" -c, --config <config> Specify the snapper configuration to use. Otherwise will perform for each snapper
-s, --subvolid <subvlid> Specify the subvolume id of the mounted BTRFS subvolume to back up to. Defaults to 5. configuration. Can list multiple configurations within quotes, space-separated
-u, --UUID <UUID> Specify the UUID of the mounted BTRFS subvolume to back up to. Otherwise will prompt." (e.g. -c "root home").
If multiple mount points are found with the same UUID, will prompt user." -n, --noconfirm Do not ask for confirmation for each configuration. Will still prompt for backup
-t, --TARGET <target> Specify the mountpoint of the BTRFS subvolume to back up to. --batch directory name on first backup"
--remote <address> Send the snapshot backup to a remote machine. The snapshot will be sent via ssh. You -s, --subvolid <subvlid> Specify the subvolume id of the mounted BTRFS subvolume to back up to. Defaults to 5.
should specify the remote machine's hostname or ip address. The 'root' user must be -u, --uuid <UUID> Specify the UUID of the mounted BTRFS subvolume to back up to. Otherwise will prompt."
permitted to login on the remote machine. If multiple mount points are found with the same UUID, will prompt user."
--dry-run perform a trial run where no changes are made. -t, --target <target> Specify the mountpoint of the BTRFS subvolume to back up to.
-v, --verbose Be more verbose on what's going on. --remote <address> Send the snapshot backup to a remote machine. The snapshot will be sent via ssh. You
should specify the remote machine's hostname or ip address. The 'root' user must be
permitted to login on the remote machine.
--dry-run perform a trial run where no changes are made.
-v, --verbose Be more verbose on what's going on.
--version show program version
EOF EOF
exit 1 exit 1
@@ -1100,10 +1162,11 @@ ssh=""
#trap 'traperror ${LINENO} $?' ERR #trap 'traperror ${LINENO} $?' ERR
trap trapkill TERM INT trap trapkill TERM INT
parse_params $@
check_prerequisites check_prerequisites
# validate commandline options, set resonable defaults
parse_params $@
# read mounted BTRFS structures # read mounted BTRFS structures
get_disk_infos get_disk_infos