echo "ℹ️ INFO: backup count $backup_count"
}
-get_machines()
+exists_machines()
{
local config="$1"
- echo "$config" | jq --raw-output '.machines | keys[]' 2> /dev/null
+ echo "$config" \
+ | jq --exit-status \
+ --raw-output '.machines | keys[]' > /dev/null 2>&1
}
get_last_backup_dir_path()
mkdir --parents "$backup_full_path"
}
+backup_remotes()
+{
+ local config="$1"
+ local backup_dir="$2"
+ local last_backup_dir_path="$3"
+ local backup_path=
+ local machines=()
+ backup_path=$(echo "$config" | jq --raw-output '.backup_path')
+ machines=($(echo "$config" | yq --raw-output '.machines | keys[]'))
+ local full_backup_path="$backup_path/$backup_dir"
+
+ local machine=
+ for machine in "${machines[@]}"; do
+ echo "ℹ️ INFO: create directory $full_backup_path/$machine"
+ done
+}
+
main()
{
local CONFIG_FILE=${CONFIG_FILE:="config.yaml"}
exists_backup_path "$config" || return $?
exists_backup_name "$config" || return $?
exists_backup_count "$config" || return $?
- local machines=
- machines=$(get_machines "$config") \
+ exists_machines "$config" \
|| errlog "$CONFIG_FILE missing machines" \
|| return $?
backup_dir=$(get_backup_dir "$config")
echo "ℹ️ INFO: backup folder $backup_dir"
create_backup_dir "$config" "$backup_dir"
+ backup_remotes "$config" "$backup_dir" "$last_backup_dir_path"
echo "✅ SUCCESS: backup"
}
create_backup_dir() {
:
}
+ backup_remotes() {
+ :
+ }
run main
find() {
echo "build/2000-01-01_01_backup"
}
+ backup_remotes() {
+ :
+ }
run main
create_backup_dir() {
:
}
+ backup_remotes() {
+ :
+ }
run main
create_backup_dir() {
:
}
+ backup_remotes() {
+ :
+ }
run main
}
@test "create backup folder" {
+ backup_remotes() {
+ :
+ }
run main
assert_success
assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup"
assert_line --index 6 "✅ SUCCESS: backup"
[ -d "build/2000-01-01_01_backup" ]
+}
+
+@test "backup remotes" {
+ run main
+
+ assert_success
+ assert_success
+ assert_line --index 0 "⭐ START: backup"
+ assert_line --index 1 "ℹ️ INFO: backup path build"
+ assert_line --index 2 "ℹ️ INFO: backup name backup"
+ assert_line --index 3 "ℹ️ INFO: backup count 15"
+ assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
+ assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup"
+ assert_line --index 6 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc1"
+ assert_line --index 7 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc2"
+ assert_line --index 8 "✅ SUCCESS: backup"
+ [ -d "build/2000-01-01_01_backup" ]
}
\ No newline at end of file