]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Evaluating additional options
authorFrank Brehm <frank@brehm-online.com>
Tue, 20 Apr 2021 06:17:59 +0000 (08:17 +0200)
committerFrank Brehm <frank@brehm-online.com>
Tue, 20 Apr 2021 06:17:59 +0000 (08:17 +0200)
bin/manual-backup

index 12d65bce6d5db5d4e1e37d72b5668e538cc84a42..6789224c9a5138fcc6b0893923208a0f36acb497 100755 (executable)
@@ -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