From e5b0e272d9358a409a9b80bca36ac3d6a309c8d2 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 20 Apr 2021 08:17:59 +0200 Subject: [PATCH] Evaluating additional options --- bin/manual-backup | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/bin/manual-backup b/bin/manual-backup index 12d65bc..6789224 100755 --- a/bin/manual-backup +++ b/bin/manual-backup @@ -68,6 +68,54 @@ TAR() { } +#------------------------------------------------------------------------------ +eval_my_options() { + + REMAINING_ARGS=() + REMAINING_OPTS=() + + if [[ "$#" -gt 0 ]] ; then + while true ; do + case "$1" in + -C|--copies) + BACKUP_COPIES="$2" + REMOVE_DATE=$(date -d "${BACKUP_COPIES} days ago" +"%Y-%m-%d") + shift + shift + ;; + -R|--remote) + REMOTE_HOSTS+=("${2}") + shift + shift + ;; + --) shift + break + ;; + *) REMAINING_OPTS+=($1) + shift + ;; + esac + done + fi + + if [[ "$#" -gt "0" ]] ; then + REMAINING_ARGS=("--") + while [[ "$#" -gt "0" ]] ; do + REMAINING_ARGS+=($1) + shift + done + fi + + debug "Keeping backup copies: ${CYAN}${BACKUP_COPIES}${NORMAL}" + debug "Separation date: '${CYAN}${REMOVE_DATE}${NORMAL}'." + if [[ "${#REMOTE_HOSTS[*]}" == "0" ]] ; then + debug "No remote host for mirroring given." + else + debug "Remote hosts for mirroring: ${CYAN}${REMOTE_HOSTS[*]}" + fi + +} + #------------------------------------------------------------------------------ get_options() { @@ -96,6 +144,8 @@ get_options() { declare -p REMAINING_ARGS fi + eval_my_options "${REMAINING_OPTS[@]}" -- "${REMAINING_ARGS[@]}" + if [[ "${#REMAINING_OPTS[@]}" -gt 0 ]] ; then error "Unknown options: ${REMAINING_OPTS[*]}" echo >&2 -- 2.39.5