]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add key for diff host backup key
authorBastian Dehn <hhaalo@arcor.de>
Sun, 25 May 2025 13:45:53 +0000 (15:45 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 25 May 2025 13:45:53 +0000 (15:45 +0200)
restore

diff --git a/restore b/restore
index 662865dfaec358a9fb04baba3e66e64615e5420c..f22aae6574ecbdb5f5c1232520a91181f2cb9619 100755 (executable)
--- a/restore
+++ b/restore
@@ -12,12 +12,13 @@ errlog()
 
 useage()
 {
-       echo "$0 -d <Datum> -n <Nummer> -r <Rechner> -p <Pfad>"
+       echo "$0 -d <date> -n <number> -r <host> -p <path>"
        echo
-       echo " -d    Datum von der Sicherung"
-       echo " -n    Nummer von der Sicherung"
-       echo " -r    Rechnerangaben <user>@<rechner>:<port>"
-       echo " -p    Vollstaendiger Pfad der Wiederhergestellt werden soll"
+       echo " -d    date from backup"
+       echo " -n    number of backup"
+       echo " -r    host <user>@<rechner>:<port>"
+       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"