]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add origin delete mode with rsync
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 08:52:27 +0000 (10:52 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 08:54:16 +0000 (10:54 +0200)
src/restore
tests/restore_tests.bats

index eda116d133d637c590003968f5a5c07902943607..a52acf726f802e5414f3e8e02fe19a3188bea9f8 100755 (executable)
@@ -126,19 +126,22 @@ restore()
        [ "$host" == "localhost" ] && hostpath="$path"
        echo "ℹ️ INFO: remote path $hostpath"
 
-       ask_restore "❓ QUESTION: Do you want restore? [N/y]" \
-               || return $?
-
        rsyncargs=("--archive"
                "--verbose"
                "--sparse"
                "--acls"
                "--hard-links"
-               "--human-readable"
-               "--rsh=ssh -p $port"
+               "--human-readable")
+       [ "$origin" == "ON" ] \
+               && echo "⚠️ WARN: DELETE MODE IS ON" \
+               && rsyncargs+=("--delete")
+       rsyncargs+=("--rsh=ssh -p $port"
                "${backup_path}/${backup_dir}/${machine}${path}"
                "$hostpath")
 
+       ask_restore "❓ QUESTION: Do you want restore? [N/y]" \
+               || return $?
+
        rsync "${rsyncargs[@]}" \
                || errlog "could not restore" \
                || return $?
@@ -164,13 +167,14 @@ main()
        local number=
        local machine=
        local path=
+       local origin="OFF"
        while getopts "d:n:r:p:ho" optname; do
                case "$optname" in
                "d") date="$OPTARG" ;;
                "n") number="$OPTARG" ;;
                "r") machine="$OPTARG" ;;
                "p") path="$OPTARG" ;;
-               "o") origin="deletemode-on" ;;
+               "o") origin="ON" ;;
                "h") useage && return 0 ;;
                *) usage && return 0 ;;
                esac
index 1fa328345999f0d7f7f85cac45c5ed2c9c91704f..ccb8b5bc1dbf7ff41c5a44817e286a8c670b0ca9 100755 (executable)
@@ -407,7 +407,6 @@ teardown() {
 
        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"
@@ -438,7 +437,6 @@ teardown() {
 
        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"
@@ -446,4 +444,34 @@ teardown() {
        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
+}
+
+# bats test_tags=restore:rsync, restore:origin
+@test "success backup machine path rsync parameter delete" {
+       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" -o
+
+       assert_success
+       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 "⚠️ WARN: DELETE MODE IS ON"
+       assert_line --index 7 "❓ QUESTION: Do you want restore? [N/y]"
+       assert_line --index 8 "✅ SUCCESS: restore"
+       assert_equal "$(awk 'NR==1 {print; exit}' "$RSYNC_LOG")" "10"
+       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")" "--delete"
+       assert_equal "$(awk 'NR==9 {print; exit}' "$RSYNC_LOG")" "--rsh=ssh -p 22"
+       assert_equal "$(awk 'NR==10 {print; exit}' "$RSYNC_LOG")" "build/test/2000-01-01_01_backup/testpc1.example.com/testpath"
+       assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "backupuser@www.example.com:/testpath"
+}