]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add directroy and file mode with restore info
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 06:37:28 +0000 (08:37 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 06:37:28 +0000 (08:37 +0200)
src/restore
tests/restore_tests.bats

index e418cf2ccdf9b4cb74802af255c4c1b15cb861fd..89049c46de61d204baeb4df687eed87e224db147 100755 (executable)
@@ -105,6 +105,16 @@ restore()
        [ -d "$backup_path/$backup_dir/$machine" ] \
                || errlog "directory $backup_path/$backup_dir/$machine not exists" \
                || return $?
+
+       local mode="directory"
+       [[ "$path" =~ /$ ]] || mode="file"
+       echo "ℹ️ INFO: restore mode $mode"
+
+       echo "ℹ️ INFO: restore path ${backup_path}/${backup_dir}/${machine}${path}"
+
+       local hostpath="$remote_user@$host:$path"
+       [ "$host" == "localhost" ] && hostpath="$path"
+       echo "ℹ️ INFO: remote path $hostpath"
 }
 
 main()
index ff161f7f3c91ae9da753957d587f9ac3f4050e4b..3a1fd65194e60a1bcbe9f69f1fc2bd6eb7f6d3cd 100755 (executable)
@@ -29,7 +29,7 @@ teardown() {
        unset RSYNC_LOG_RUNS
 }
 
-# bats test_tags=backup:start,backup:cmd
+# bats test_tags=restore:start,restore:cmd
 @test "failure yq command not found" {
        command() {
                return 1
@@ -41,7 +41,7 @@ teardown() {
        assert_line --index 0 "❌ ERROR: command yq not found"
 }
 
-# bats test_tags=backup:start,backup:cmd
+# bats test_tags=restore:start,restore:cmd
 @test "failure jq command not found" {
        command() {
                [ "$2" != "jq" ] || return 1
@@ -53,7 +53,7 @@ teardown() {
        assert_line --index 0 "❌ ERROR: command jq not found"
 }
 
-# bats test_tags=backup:start,backup:cmd
+# bats test_tags=restore:start,restore:cmd
 @test "failure rsync command not found" {
        command() {
                [ "$2" != "rsync" ] || return 1
@@ -65,7 +65,7 @@ teardown() {
        assert_line --index 0 "❌ ERROR: command rsync not found"
 }
 
-# bats test_tags=backup:start,backup:cmd
+# bats test_tags=restore:start,restore:cmd
 @test "failure ssh command not found" {
        command() {
                [ "$2" != "ssh" ] || return 1
@@ -77,7 +77,7 @@ teardown() {
        assert_line --index 0 "❌ ERROR: command ssh not found"
 }
 
-# bats test_tags=backup:start,backup:config
+# bats test_tags=restore:start,restore:config
 @test "failure config.yaml not found" {
        exists_config_file() {
                errlog "file config.yaml not found"
@@ -90,7 +90,7 @@ teardown() {
        assert_line --index 0 "❌ ERROR: file config.yaml not found"
 }
 
-# bats test_tags=backup:start,backup:config
+# bats test_tags=restore:start,restore:config
 @test "failure load config.yaml" {
        yq() {
                return 1
@@ -102,7 +102,7 @@ teardown() {
        assert_line --index 0 "❌ ERROR: failed to load src/config-example.yaml"
 }
 
-# bats test_tags=backup:start,backup:config
+# bats test_tags=restore:start,restore:config
 @test "failure no backup path in config" {
        yq() {
                echo '{}'
@@ -115,7 +115,7 @@ teardown() {
        assert_line --index 1 "❌ ERROR: src/config-example.yaml missing backup_path"
 }
 
-# bats test_tags=backup:start,backup:config
+# bats test_tags=restore:start,restore:config
 @test "failure no backup name in config" {
        yq() {
                echo '{"backup_path": "path"}'
@@ -129,7 +129,7 @@ teardown() {
        assert_line --index 2 "❌ ERROR: src/config-example.yaml missing backup_name"
 }
 
-# bats test_tags=backup:start,backup:config
+# bats test_tags=restore:start,restore:config
 @test "failure no machines in config" {
        yq() {
                echo '{
@@ -147,7 +147,7 @@ teardown() {
        assert_line --index 3 "❌ ERROR: src/config-example.yaml missing machines"
 }
 
-# bats test_tags=backup:start,backup:param
+# bats test_tags=restore:start,restore:param
 @test "failure date parameter missing" {
        run main
 
@@ -158,7 +158,7 @@ teardown() {
        assert_line --index 3 "❌ ERROR: missing date (-d)"
 }
 
-# bats test_tags=backup:start,backup:param
+# bats test_tags=restore:start,restore:param
 @test "failure number parameter missing" {
        run main -d "2000-01-01"
 
@@ -169,7 +169,7 @@ teardown() {
        assert_line --index 3 "❌ ERROR: missing number (-n)"
 }
 
-# bats test_tags=backup:start,backup:param
+# bats test_tags=restore:start,restore:param
 @test "failure number parameter must two digits" {
        run main -d "2000-01-01" -n "1"
 
@@ -180,7 +180,7 @@ teardown() {
        assert_line --index 3 "❌ ERROR: number must two digits"
 }
 
-# bats test_tags=backup:start,backup:param
+# bats test_tags=restore:start,restore:param
 @test "failure machine parameter missing" {
        run main -d "2000-01-01" -n "01"
 
@@ -191,7 +191,7 @@ teardown() {
        assert_line --index 3 "❌ ERROR: missing machine (-r)"
 }
 
-# bats test_tags=backup:start,backup:param
+# bats test_tags=restore:start,restore:param
 @test "failure path parameter missing" {
        run main -d "2000-01-01" -n "01" -r "testpc1.example.com"
 
@@ -202,7 +202,7 @@ teardown() {
        assert_line --index 3 "❌ ERROR: missing path (-p)"
 }
 
-# bats test_tags=backup:config
+# bats test_tags=restore:config
 @test "failure config missing remote user" {
        yq() {
                echo '{
@@ -223,7 +223,7 @@ teardown() {
        assert_line --index 3 "❌ ERROR: missing remote user in src/config-example.yaml"
 }
 
-# bats test_tags=backup:config
+# bats test_tags=restore:config
 @test "failure config missing host" {
        yq() {
                echo '{
@@ -246,7 +246,7 @@ teardown() {
        assert_line --index 3 "❌ ERROR: missing host in src/config-example.yaml"
 }
 
-# bats test_tags=backup:config
+# bats test_tags=restore:config
 @test "failure config missing remote port" {
        yq() {
                echo '{
@@ -270,7 +270,7 @@ teardown() {
        assert_line --index 3 "❌ ERROR: missing port in src/config-example.yaml"
 }
 
-# bats test_tags=backup:pathcheck
+# bats test_tags=restore:pathcheck
 @test "failure no backup directory" {
        run main -d "2000-01-01" -n "01" -r "testpc1.example.com" -p "/testpath"
 
@@ -281,7 +281,7 @@ teardown() {
        assert_line --index 3 "❌ ERROR: directory build/test/2000-01-01_01_backup not exists"
 }
 
-# bats test_tags=backup:pathcheck
+# bats test_tags=restore:pathcheck
 @test "failure no backup directory machine" {
        mkdir --parents "build/test/2000-01-01_01_backup"
 
@@ -292,4 +292,64 @@ teardown() {
        assert_line --index 1 "ℹ️ INFO: backup path build/test"
        assert_line --index 2 "ℹ️ INFO: backup name backup"
        assert_line --index 3 "❌ ERROR: directory build/test/2000-01-01_01_backup/testpc1.example.com not exists"
+}
+
+# bats test_tags=restore:mode
+@test "success directory mode" {
+       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_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 directory"
+       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/"
+}
+
+# bats test_tags=restore:mode
+@test "success file mode" {
+       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_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"
+}
+
+# bats test_tags=restore:mode
+@test "success directory mode on localhost" {
+       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 directory"
+       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:mode
+@test "success file mode on localhost" {
+       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"
 }
\ No newline at end of file