]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add useage help for restore
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 09:11:59 +0000 (11:11 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 09:11:59 +0000 (11:11 +0200)
src/man/restore.1
src/restore
tests/restore_tests.bats

index cad35024de0766419aa04f400f55e0001a210783..22e82f1231639476271d09949547bec8aa6a456a 100644 (file)
@@ -11,7 +11,7 @@ restore -d <date> -n <number> -r <host> -p <path> [-o -h]
 .EX
 -d <date>     date from backup
 -n <number>   number of backup
--r <host>     host must ssh conform <user>@<machine>:<port>
+-r <host>     host name
 -p <path>     path to restore on destination
 -o            origin deletion mode - deletes files on destination
 -h            show help
index a52acf726f802e5414f3e8e02fe19a3188bea9f8..c9397cb3a2f549bf468a91389e8772e631dcf35b 100755 (executable)
@@ -9,6 +9,19 @@ errlog()
        return $lastexit
 }
 
+useage()
+{
+       echo "restore -d <date> -n <number> -r <host> -p <path> [-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} ]] \
index ccb8b5bc1dbf7ff41c5a44817e286a8c670b0ca9..6b4cbf70d4be20794d0969cfe503a2d135ff4c3d 100755 (executable)
@@ -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 <date> -n <number> -r <host> -p <path> [-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"
+}