From 97152d1b42926c7d9ea4b45f3b13bcd22bbdcc52 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 25 May 2025 15:45:53 +0200 Subject: [PATCH] add key for diff host backup key --- restore | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/restore b/restore index 662865d..f22aae6 100755 --- a/restore +++ b/restore @@ -12,12 +12,13 @@ errlog() useage() { - echo "$0 -d -n -r -p " + echo "$0 -d -n -r -p " echo - echo " -d Datum von der Sicherung" - echo " -n Nummer von der Sicherung" - echo " -r Rechnerangaben @:" - echo " -p Vollstaendiger Pfad der Wiederhergestellt werden soll" + echo " -d date from backup" + echo " -n number of backup" + echo " -r host @:" + echo " -p path" + echo " -k key for host in config" echo } @@ -36,6 +37,7 @@ restore() local number="$2" local machine="$3" local path="$4" + local key="$5" local backup_root=$(cat config.yaml \ | yq --raw-output '.backup_path') local backup_name=$(cat config.yaml \ @@ -58,11 +60,14 @@ restore() || errlog "could not find directory $backup_root/$backup_dir" \ || return $? - [ -d "$backup_root/$backup_dir/$remote_machine" ] \ - || errlog "could not find directory $backup_root/$backup_dir/$remote_machine" \ + local restore_prefix_path="$backup_root/$backup_dir/$remote_machine" + [ -n "$key" ] \ + && restore_prefix_path="$backup_root/$backup_dir/$key" + [ -d "$restore_prefix_path" ] \ + || errlog "could not find directory $restore_prefix_path" \ || return $? - local restore_path="$backup_root/$backup_dir/$remote_machine$path" + local restore_path="$restore_prefix_path$path" local remote_path="$remote_user@$remote_machine:$path" local mode="directory" @@ -112,12 +117,14 @@ main() local number= local machine= local path= + local key= echo "⭐ START: restore" - while getopts "d:n:r:p:h" optname; do + while getopts "d:k:n:r:p:h" optname; do case "$optname" in "d") date="$OPTARG" ;; + "k") key="$OPTARG" ;; "n") number="$OPTARG" ;; "r") machine="$OPTARG" ;; "p") path="$OPTARG" ;; @@ -143,7 +150,7 @@ main() || return $? [ -n "$path" ] || errlog "missing path (-p)" || return $? - restore "$date" "$number" "$machine" "$path" \ + restore "$date" "$number" "$machine" "$path" "$key" \ || return $? echo "✅ SUCCESS: restore" -- 2.39.5