]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
change variable checks for config
authorBastian Dehn <hhaalo@arcor.de>
Sat, 24 May 2025 17:42:31 +0000 (19:42 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 24 May 2025 17:42:31 +0000 (19:42 +0200)
backup

diff --git a/backup b/backup
index a719e81d93503292867430f70e087bd64c7bf48f..32d448658aea79d77e93948fd703e87e81f4cdaa 100755 (executable)
--- 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"