echo " -r host <user>@<rechner>:<port>"
echo " -p path"
echo " -o restore origin (delete mode)"
- echo " -k key for host in config"
echo
}
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 $?
local restore_path="$restore_prefix_path$path"
local remote_path="$remote_user@$remote_machine:$path"
-
local mode="directory"
[[ "$path" =~ /$ ]] || mode="file"
echo
[ "$origin" == "deletemode-on" ] \
- && deletemode="--delete" \
+ && local deletemode="--delete" \
&& echo "⚠️ WARN: delete mode on" && echo
local ask_restore="N"
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" ;;
|| errlog "number must two digits" \
|| return $?
[ -n "$machine" ] || errlog "missing machine (-r)" || return $?
- [[ "$machine" =~ .*@.*:[[:digit:]]* ]] \
- || errlog "machine format must <user>@<host>:<port>" \
- || 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"