.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
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 \
|| 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=
"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} ]] \
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"
+}