From 530ec496fa307cc3215f89f2ee9f1404b9bc6969 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 16 Aug 2026 11:11:59 +0200 Subject: [PATCH] add useage help for restore --- src/man/restore.1 | 2 +- src/restore | 27 ++++++++++++++++++++------- tests/restore_tests.bats | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/man/restore.1 b/src/man/restore.1 index cad3502..22e82f1 100644 --- a/src/man/restore.1 +++ b/src/man/restore.1 @@ -11,7 +11,7 @@ restore -d -n -r -p [-o -h] .EX -d date from backup -n number of backup --r host must ssh conform @: +-r host name -p path to restore on destination -o origin deletion mode - deletes files on destination -h show help diff --git a/src/restore b/src/restore index a52acf7..c9397cb 100755 --- a/src/restore +++ b/src/restore @@ -9,6 +9,19 @@ errlog() return $lastexit } +useage() +{ + echo "restore -d -n -r -p [-o -h]" + echo + echo " -d date from backup" + echo " -n number of backup" + echo " -r host name" + echo " -p path to restore on destination" + echo " -o origin deletion mode - delete files on destination" + echo " -h show help" + echo +} + exists_needed_commands() { command -v yq > /dev/null \ @@ -156,12 +169,6 @@ main() || errlog "failed to load $CONFIG_FILE" \ || return $? echo "⭐ START: restore" - exists_backup_path "$config" || return $? - exists_backup_name "$config" || return $? - exists_machines "$config" \ - || errlog "$CONFIG_FILE missing machines" \ - || return $? - local optname= local date= local number= @@ -176,10 +183,16 @@ main() "p") path="$OPTARG" ;; "o") origin="ON" ;; "h") useage && return 0 ;; - *) usage && return 0 ;; + *) return 0 ;; esac done + exists_backup_path "$config" || return $? + exists_backup_name "$config" || return $? + exists_machines "$config" \ + || errlog "$CONFIG_FILE missing machines" \ + || return $? + [ -n "$date" ] || errlog "missing date (-d)" || return $? [ -n "$number" ] || errlog "missing number (-n)" || return $? [[ "$number" =~ [[:digit:]]{2} ]] \ diff --git a/tests/restore_tests.bats b/tests/restore_tests.bats index ccb8b5b..6b4cbf7 100755 --- a/tests/restore_tests.bats +++ b/tests/restore_tests.bats @@ -475,3 +475,21 @@ teardown() { 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" } + +# bats test_tags=restore:rsync, restore:origin +@test "success show help useage" { + mkdir --parents "build/test/2000-01-01_01_backup/testpc1.example.com/testpath" + RSYNC_LOG_RUNS="1" + + run main -h + + assert_success + assert_line --index 0 "⭐ START: restore" + assert_line --index 1 "restore -d -n -r -p [-o -h]" + assert_line --index 2 " -d date from backup" + assert_line --index 3 " -n number of backup" + assert_line --index 4 " -r host name" + assert_line --index 5 " -p path to restore on destination" + assert_line --index 6 " -o origin deletion mode - delete files on destination" + assert_line --index 7 " -h show help" +} -- 2.47.3