From: Bastian Dehn Date: Wed, 5 Aug 2026 13:26:28 +0000 (+0200) Subject: add test for backup remotes X-Git-Tag: v1.0.6^2~1^2~58 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=48b2ae962cecfbc380427d5979acedd8876222ac;p=simple-backup.git add test for backup remotes --- diff --git a/src/backup b/src/backup index 0f8d4b2..02c4a5a 100755 --- a/src/backup +++ b/src/backup @@ -67,10 +67,12 @@ exists_backup_count() echo "ℹ️ INFO: backup count $backup_count" } -get_machines() +exists_machines() { local config="$1" - echo "$config" | jq --raw-output '.machines | keys[]' 2> /dev/null + echo "$config" \ + | jq --exit-status \ + --raw-output '.machines | keys[]' > /dev/null 2>&1 } get_last_backup_dir_path() @@ -120,6 +122,23 @@ create_backup_dir() mkdir --parents "$backup_full_path" } +backup_remotes() +{ + local config="$1" + local backup_dir="$2" + local last_backup_dir_path="$3" + local backup_path= + local machines=() + backup_path=$(echo "$config" | jq --raw-output '.backup_path') + machines=($(echo "$config" | yq --raw-output '.machines | keys[]')) + local full_backup_path="$backup_path/$backup_dir" + + local machine= + for machine in "${machines[@]}"; do + echo "ℹ️ INFO: create directory $full_backup_path/$machine" + done +} + main() { local CONFIG_FILE=${CONFIG_FILE:="config.yaml"} @@ -136,8 +155,7 @@ main() exists_backup_path "$config" || return $? exists_backup_name "$config" || return $? exists_backup_count "$config" || return $? - local machines= - machines=$(get_machines "$config") \ + exists_machines "$config" \ || errlog "$CONFIG_FILE missing machines" \ || return $? @@ -149,6 +167,7 @@ main() backup_dir=$(get_backup_dir "$config") echo "ℹ️ INFO: backup folder $backup_dir" create_backup_dir "$config" "$backup_dir" + backup_remotes "$config" "$backup_dir" "$last_backup_dir_path" echo "✅ SUCCESS: backup" } diff --git a/src/config-example.yaml b/src/config-example.yaml index 5b407d7..e1c2ebc 100644 --- a/src/config-example.yaml +++ b/src/config-example.yaml @@ -3,7 +3,18 @@ backup_name: backup backup_count: 15 machines: - testpc: + testpc1: + remote_user: backupuser + host: www.example.com + port: 22 + # excludes optional + excludes: + - /home/user/.cache + - /home/user/.local + pathes: + - /etc + - /home/user + testpc2: remote_user: backupuser host: www.example.com port: 22 diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index 1189759..fc30943 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -168,6 +168,9 @@ teardown() { create_backup_dir() { : } + backup_remotes() { + : + } run main @@ -186,6 +189,9 @@ teardown() { find() { echo "build/2000-01-01_01_backup" } + backup_remotes() { + : + } run main @@ -202,6 +208,9 @@ teardown() { create_backup_dir() { : } + backup_remotes() { + : + } run main @@ -219,6 +228,9 @@ teardown() { create_backup_dir() { : } + backup_remotes() { + : + } run main @@ -234,6 +246,9 @@ teardown() { } @test "create backup folder" { + backup_remotes() { + : + } run main assert_success @@ -245,4 +260,21 @@ teardown() { assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup" assert_line --index 6 "✅ SUCCESS: backup" [ -d "build/2000-01-01_01_backup" ] +} + +@test "backup remotes" { + run main + + assert_success + assert_success + assert_line --index 0 "⭐ START: backup" + assert_line --index 1 "ℹ️ INFO: backup path build" + assert_line --index 2 "ℹ️ INFO: backup name backup" + assert_line --index 3 "ℹ️ INFO: backup count 15" + assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup" + assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup" + assert_line --index 6 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc1" + assert_line --index 7 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc2" + assert_line --index 8 "✅ SUCCESS: backup" + [ -d "build/2000-01-01_01_backup" ] } \ No newline at end of file