From 93cc03902ef552118ccde4e81f2690c954c5f38b Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 16 Aug 2026 10:29:54 +0200 Subject: [PATCH] add restore rsync operation --- src/restore | 16 +++++++++++++ tests/restore_tests.bats | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/src/restore b/src/restore index 9fb35a5..eda116d 100755 --- a/src/restore +++ b/src/restore @@ -128,6 +128,20 @@ restore() ask_restore "❓ QUESTION: Do you want restore? [N/y]" \ || return $? + + rsyncargs=("--archive" + "--verbose" + "--sparse" + "--acls" + "--hard-links" + "--human-readable" + "--rsh=ssh -p $port" + "${backup_path}/${backup_dir}/${machine}${path}" + "$hostpath") + + rsync "${rsyncargs[@]}" \ + || errlog "could not restore" \ + || return $? } main() @@ -172,6 +186,8 @@ main() restore "$config" "$date" "$number" "$machine" "$path" "$origin" \ || return $? + + echo "✅ SUCCESS: restore" } [ "$TESTMODE" == "ON" ] && return 0 diff --git a/tests/restore_tests.bats b/tests/restore_tests.bats index ffdba8e..1fa3283 100755 --- a/tests/restore_tests.bats +++ b/tests/restore_tests.bats @@ -396,4 +396,54 @@ teardown() { assert_line --index 4 "ℹ️ INFO: restore path build/test/2000-01-01_01_backup/onlylocal/testpath" assert_line --index 5 "ℹ️ INFO: remote path /testpath" assert_line --index 6 "❓ QUESTION: Do you want restore? [N/y]" +} + +# bats test_tags=restore:rsync +@test "success backup machine path rsync parameters" { + mkdir --parents "build/test/2000-01-01_01_backup/testpc1.example.com/testpath" + RSYNC_LOG_RUNS="1" + + run main -d "2000-01-01" -n "01" -r "testpc1.example.com" -p "/testpath" + + assert_success + assert_line --index 0 "⭐ START: restore" + assert_line --index 0 "⭐ START: restore" + assert_line --index 1 "ℹ️ INFO: backup path build/test" + assert_line --index 2 "ℹ️ INFO: backup name backup" + assert_line --index 3 "ℹ️ INFO: restore mode file" + assert_line --index 4 "ℹ️ INFO: restore path build/test/2000-01-01_01_backup/testpc1.example.com/testpath" + assert_line --index 5 "ℹ️ INFO: remote path backupuser@www.example.com:/testpath" + assert_line --index 6 "❓ QUESTION: Do you want restore? [N/y]" + assert_line --index 7 "✅ SUCCESS: restore" + assert_equal "$(awk 'NR==1 {print; exit}' "$RSYNC_LOG")" "9" + assert_equal "$(awk 'NR==2 {print; exit}' "$RSYNC_LOG")" "--archive" + assert_equal "$(awk 'NR==3 {print; exit}' "$RSYNC_LOG")" "--verbose" + assert_equal "$(awk 'NR==4 {print; exit}' "$RSYNC_LOG")" "--sparse" + assert_equal "$(awk 'NR==5 {print; exit}' "$RSYNC_LOG")" "--acls" + assert_equal "$(awk 'NR==6 {print; exit}' "$RSYNC_LOG")" "--hard-links" + assert_equal "$(awk 'NR==7 {print; exit}' "$RSYNC_LOG")" "--human-readable" + assert_equal "$(awk 'NR==8 {print; exit}' "$RSYNC_LOG")" "--rsh=ssh -p 22" + assert_equal "$(awk 'NR==9 {print; exit}' "$RSYNC_LOG")" "build/test/2000-01-01_01_backup/testpc1.example.com/testpath" + assert_equal "$(awk 'NR==10 {print; exit}' "$RSYNC_LOG")" "backupuser@www.example.com:/testpath" +} + +# bats test_tags=restore:rsync +@test "failure rsync failed" { + rsync() { + return 1 + } + mkdir --parents "build/test/2000-01-01_01_backup/testpc1.example.com/testpath" + + run main -d "2000-01-01" -n "01" -r "testpc1.example.com" -p "/testpath" + + assert_failure + assert_line --index 0 "⭐ START: restore" + assert_line --index 0 "⭐ START: restore" + assert_line --index 1 "ℹ️ INFO: backup path build/test" + assert_line --index 2 "ℹ️ INFO: backup name backup" + assert_line --index 3 "ℹ️ INFO: restore mode file" + assert_line --index 4 "ℹ️ INFO: restore path build/test/2000-01-01_01_backup/testpc1.example.com/testpath" + assert_line --index 5 "ℹ️ INFO: remote path backupuser@www.example.com:/testpath" + assert_line --index 6 "❓ QUESTION: Do you want restore? [N/y]" + assert_line --index 7 "❌ ERROR: could not restore" } \ No newline at end of file -- 2.47.3