From 0dd3f5d03c341736d78e01b6af96b0b53b798739 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 24 May 2025 19:42:31 +0200 Subject: [PATCH] change variable checks for config --- backup | 58 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/backup b/backup index a719e81..32d4486 100755 --- a/backup +++ b/backup @@ -58,10 +58,25 @@ backup_remote_pathes() local last_backup_dir_path="$3" local hardlinkopt= local remote_user=$(cat config.yaml \ - | yq -r ".machines.\"$machine\".remote_user") - local host=$(cat config.yaml | yq -r ".machines.\"$machine\".host") - local port=$(cat config.yaml | yq -r ".machines.\"$machine\".port") - local pathes=$(cat config.yaml | yq -r ".machines.\"$machine\".pathes[]") + | yq --raw-output ".machines.\"$machine\".remote_user") + [ -n "$remote_user" ] && [ $remote_user != "null" ] \ + || errlog "config.yaml missing remote_user for $machine" \ + || return $? + local host=$(cat config.yaml \ + | yq --raw-output ".machines.\"$machine\".host") + [ -n "$host" ] && [ "$host" != "null" ] \ + || errlog "config.yaml missing host for $machine" \ + || return $? + local port=$(cat config.yaml \ + | yq --raw-output ".machines.\"$machine\".port") + [ -n "$port" ] && [ "$port" != "null" ] \ + || errlog "config.yaml missing port for $machine" \ + || return $? + local pathes=$(cat config.yaml \ + | yq --raw-output ".machines.\"$machine\".pathes[]") + [ -n "$pathes" ] \ + || errlog "config.yaml missing pathes for $machine" \ + || return $? local YELLOW="\e[0;33m" local LIGHTPURPLE="\e[1;35m" @@ -98,7 +113,10 @@ backup_remotes() local backup_path="$1" local last_backup_dir_path="$2" local hardlinkopt= - local machines=$(cat config.yaml | yq -r '.machines | keys[]') + local machines=$(cat config.yaml | yq --raw-output '.machines | keys[]') + [ -n "$machines" ] \ + || errlog "config.yaml no machines" \ + || return $? for machine in $machines; do echo "ℹ️ INFO: create direcotry $backup_path/$machine" @@ -248,27 +266,26 @@ main() || errlog "file config.yaml not found" \ || return $? - backup_path=$(cat config.yaml | yq -r '.backup_path') - backup_name=$(cat config.yaml | yq -r '.backup_name') - backup_count=$(cat config.yaml | yq -r '.backup_count') + backup_path=$(cat config.yaml | yq --raw-output '.backup_path') + backup_name=$(cat config.yaml | yq --raw-output '.backup_name') + backup_count=$(cat config.yaml | yq --raw-output '.backup_count') [ -n "$backup_path" ] && [ "$backup_path" != "null" ] \ - || errlog "missing backup_path in config.yaml" \ + || errlog "config.yaml missing backup_path" \ || return $? [ -d "$backup_path" ] \ || errlog "directory $backup_path not exists" \ || return $? echo "ℹ️ INFO: backup path $backup_path" [ -n "$backup_name" ] && [ "$backup_name" != "null" ] \ - || errlog "missing backup_name in config.yaml" \ + || errlog "config.yaml missing backup_name" \ || return $? echo "ℹ️ INFO: backup name $backup_name" [ -n "$backup_count" ] && [ "$backup_count" != "null" ] \ - || errlog "missing backup_count in config.yaml" \ + || errlog "config.yaml missing backup_count" \ || return $? echo "ℹ️ INFO: backup count $backup_count" - local backup_dir=$(get_backup_dir \ "$backup_path" \ "$backup_name") @@ -281,10 +298,19 @@ main() "$backup_name") echo "ℹ️ INFO: last backup dir path $last_backup_dir_path" - backup_remotes "$backup_full_path" "$last_backup_dir_path" || return $? - make_history "$backup_path" || return $? - check_backup_date || return $? - cleanup_backups "$backup_path" "$backup_name" $backup_count \ + backup_remotes \ + "$backup_full_path" \ + "$last_backup_dir_path" \ + || return $? + make_history \ + "$backup_path" \ + || return $? + check_backup_date \ + || return $? + cleanup_backups \ + "$backup_path" \ + "$backup_name" \ + $backup_count \ || return $? echo "✅ SUCCESS: backup" -- 2.39.5