From: Bastian Dehn Date: Tue, 27 May 2025 16:58:06 +0000 (+0200) Subject: change get machine from config yaml X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=e0e966c71b6e6b0ac3d932b9d060aacc8576db19;p=simple-backup.git change get machine from config yaml --- diff --git a/restore b/restore index e53cd28..a800a42 100755 --- a/restore +++ b/restore @@ -19,7 +19,6 @@ useage() echo " -r host @:" echo " -p path" echo " -o restore origin (delete mode)" - echo " -k key for host in config" echo } @@ -39,33 +38,47 @@ restore() local machine="$3" local path="$4" local origin="$5" - local key="$6" - local deletemode= - local backup_root=$(cat config.yaml \ - | yq --raw-output '.backup_path') - local backup_name=$(cat config.yaml \ - | yq --raw-output '.backup_name') - [ -d "$backup_root" ] \ - || errlog "could not find directory $backup_root" \ + local backup_path=$(cat config.yaml \ + | yq --raw-output ".backup_path") + local backup_name=$(cat config.yaml \ + | yq --raw-output ".backup_name") + local machine=$(cat config.yaml \ + | yq --raw-output \ + ".machines | keys[] | select(. == \"$machine\")") + local remote_user=$(cat config.yaml \ + | yq --raw-output ".machines.\"$machine\".remote_user") + local remote_machine=$(cat config.yaml \ + | yq --raw-output ".machines.\"$machine\".host") + local remote_port=$(cat config.yaml \ + | yq --raw-output ".machines.\"$machine\".port") + + [ -d "$backup_path" ] \ + || errlog "could not find directory $backup_path" \ + || return $? + [ -n "$machine" ] \ + || errlog "config.yaml missing machine" \ || return $? [ "$backup_name" != "null" ] \ - || errlog "missing backup name" \ + || errlog "config.yaml missing backup_name" \ + || return $? + [ "$remote_user" != "null" ] \ + || errlog "config.yaml missing remote_user" \ + || return $? + [ "$remote_machine" != "null" ] \ + || errlog "config.yaml missing host" \ + || return $? + [ "$remote_port" != "null" ] \ + || errlog "config.yaml missing port" \ || return $? - local remote_user=${machine%%@*} - local remote_machine=${machine%:*} - local remote_machine=${remote_machine#*@} - local remote_port=${machine##*:} local backup_dir="$date"_"$number"_"$backup_name" - [ -d "$backup_root/$backup_dir" ] \ - || errlog "could not find directory $backup_root/$backup_dir" \ + [ -d "$backup_path/$backup_dir" ] \ + || errlog "could not find directory $backup_path/$backup_dir" \ || return $? - local restore_prefix_path="$backup_root/$backup_dir/$remote_machine" - [ -n "$key" ] \ - && restore_prefix_path="$backup_root/$backup_dir/$key" + local restore_prefix_path="$backup_path/$backup_dir/$machine" [ -d "$restore_prefix_path" ] \ || errlog "could not find directory $restore_prefix_path" \ || return $? @@ -73,7 +86,6 @@ restore() local restore_path="$restore_prefix_path$path" local remote_path="$remote_user@$remote_machine:$path" - local mode="directory" [[ "$path" =~ /$ ]] || mode="file" @@ -89,7 +101,7 @@ restore() echo [ "$origin" == "deletemode-on" ] \ - && deletemode="--delete" \ + && local deletemode="--delete" \ && echo "⚠️ WARN: delete mode on" && echo local ask_restore="N" @@ -134,7 +146,6 @@ main() while getopts "d:k:n:r:p:ho" optname; do case "$optname" in "d") date="$OPTARG" ;; - "k") key="$OPTARG" ;; "n") number="$OPTARG" ;; "r") machine="$OPTARG" ;; "p") path="$OPTARG" ;; @@ -156,12 +167,9 @@ main() || errlog "number must two digits" \ || return $? [ -n "$machine" ] || errlog "missing machine (-r)" || return $? - [[ "$machine" =~ .*@.*:[[:digit:]]* ]] \ - || errlog "machine format must @:" \ - || return $? [ -n "$path" ] || errlog "missing path (-p)" || return $? - restore "$date" "$number" "$machine" "$path" "$origin" "$key" \ + restore "$date" "$number" "$machine" "$path" "$origin" \ || return $? echo "✅ SUCCESS: restore"