From: Bastian Dehn Date: Sun, 16 Aug 2026 08:08:30 +0000 (+0200) Subject: add question to restore X-Git-Tag: v1.0.7^2~3^2~4 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=a2387865d35ad2f695d309f4af23665b81e026f6;p=simple-backup.git add question to restore --- diff --git a/src/restore b/src/restore index 89049c4..9fb35a5 100755 --- a/src/restore +++ b/src/restore @@ -64,6 +64,16 @@ exists_machines() --raw-output '.machines | keys[]' > /dev/null 2>&1 } +ask_restore() +{ + local prompt="$1" + local answer= + + read -rp "$prompt" answer + + [ "${answer,,}" == "y" ] +} + restore() { local config="$1" @@ -115,6 +125,9 @@ restore() local hostpath="$remote_user@$host:$path" [ "$host" == "localhost" ] && hostpath="$path" echo "ℹ️ INFO: remote path $hostpath" + + ask_restore "❓ QUESTION: Do you want restore? [N/y]" \ + || return $? } main() diff --git a/tests/restore_tests.bats b/tests/restore_tests.bats index 3a1fd65..ffdba8e 100755 --- a/tests/restore_tests.bats +++ b/tests/restore_tests.bats @@ -17,6 +17,10 @@ setup() { echo "${#@}" > "$RSYNC_LOG" printf "%s\n" "$@" >> "$RSYNC_LOG" } + ask_restore() { + echo "$1" + return 0 + } } teardown() { @@ -352,4 +356,44 @@ teardown() { assert_line --index 3 "ℹ️ INFO: restore mode file" assert_line --index 4 "ℹ️ INFO: restore path build/test/2000-01-01_01_backup/onlylocal/testpath" assert_line --index 5 "ℹ️ INFO: remote path /testpath" +} + +# bats test_tags=restore:question +@test "success question with answer default no" { + ask_restore() { + echo "$1" + return 1 + } + mkdir --parents "build/test/2000-01-01_01_backup/onlylocal/testpath" + + run main -d "2000-01-01" -n "01" -r "onlylocal" -p "/testpath" + + assert_failure + 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/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:question +@test "success question with answer default yes" { + ask_restore() { + echo "$1" + return 0 + } + mkdir --parents "build/test/2000-01-01_01_backup/onlylocal/testpath" + + run main -d "2000-01-01" -n "01" -r "onlylocal" -p "/testpath" + + 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/onlylocal/testpath" + assert_line --index 5 "ℹ️ INFO: remote path /testpath" + assert_line --index 6 "❓ QUESTION: Do you want restore? [N/y]" } \ No newline at end of file