local host=
remote_user=$(echo "$config" \
- | jq --raw-output ".machines.$machine.remote_user")
+ | jq --raw-output ".machines.\"$machine\".remote_user")
[ "$remote_user" != "null" ] \
|| errlog "missing remote user for $machine" \
|| return $?
host=$(echo "$config" \
- | jq --raw-output ".machines.$machine.host")
+ | jq --raw-output ".machines.\"$machine\".host")
[ "$host" != "null" ] \
|| errlog "missing host for $machine" \
|| return $?
port=$(echo "$config" \
- | jq --raw-output ".machines.$machine.port")
+ | jq --raw-output ".machines.\"$machine\".port")
[ "$port" != "null" ] \
|| errlog "missing port for $machine" \
|| return $?
local excludes=()
mapfile -t excludes < <(echo "$config" \
- | jq --raw-output ".machines.$machine.excludes[]" \
+ | jq --raw-output ".machines.\"$machine\".excludes[]" \
2> /dev/null)
[ "${#excludes[@]}" -eq "0" ] \
|| echo "ℹ️ INFO: machine $machine; excludes ${excludes[*]}"
local last_backup_dir_path="$4"
local pathes=()
mapfile -t pathes < <(echo "$config" \
- | jq --raw-output ".machines.$machine.pathes[]" \
+ | jq --raw-output ".machines.\"$machine\".pathes[]" \
2> /dev/null)
[ "${#pathes[@]}" -ne "0" ] \
|| errlog "missing pathes for machine $machine" \
assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup"
assert_line --index 6 "💾 START: backup run"
- assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1"
+ assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com"
assert_line --index 8 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc2"
assert_line --index 9 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/onlylocal"
assert_line --index 10 "ℹ️ INFO: 2000-01-01T23:30:45+02:00 [none] created 2000-01-01_01_backup -> build/test/backup.log"
assert_line --index 15 "🏁 FINISH: backup run"
assert_line --index 16 "✅ SUCCESS: backup"
[ -d "build/test/2000-01-01_01_backup" ]
- [ -d "build/test/2000-01-01_01_backup/testpc1" ]
+ [ -d "build/test/2000-01-01_01_backup/testpc1.example.com" ]
[ -d "build/test/2000-01-01_01_backup/testpc2" ]
}
assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup"
assert_line --index 6 "💾 START: backup run"
- assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1"
+ assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com"
assert_line --index 8 "################################################################################"
- assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/etc${RESET}"
+ assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/etc${RESET}"
assert_line --index 10 "################################################################################"
assert_line --index 11 "################################################################################"
- assert_line --index 12 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/home/user${RESET}"
+ assert_line --index 12 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/home/user${RESET}"
assert_line --index 13 "################################################################################"
assert_line --index 14 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc2"
assert_line --index 15 "################################################################################"
"backup_name": "backup",
"backup_count": 15,
"machines": {
- "testpc1": null
+ "testpc1.example.com": null
}
}'
}
assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup"
assert_line --index 6 "💾 START: backup run"
- assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1"
- assert_line --index 8 "❌ ERROR: missing pathes for machine testpc1"
+ assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com"
+ assert_line --index 8 "❌ ERROR: missing pathes for machine testpc1.example.com"
}
# bats test_tags=backup:info
"backup_name": "backup",
"backup_count": 15,
"machines": {
- "testpc1": {
+ "testpc1.example.com": {
"pathes": ["/home/user"]
}
}
assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup"
assert_line --index 6 "💾 START: backup run"
- assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1"
+ assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com"
assert_line --index 8 "################################################################################"
- assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/home/user${RESET}"
- assert_line --index 10 "❌ ERROR: missing remote user for testpc1"
+ assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/home/user${RESET}"
+ assert_line --index 10 "❌ ERROR: missing remote user for testpc1.example.com"
}
# bats test_tags=backup:info
"backup_name": "backup",
"backup_count": 15,
"machines": {
- "testpc1": {
+ "testpc1.example.com": {
"remote_user": "testuser",
"pathes": ["/home/user"]
}
assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup"
assert_line --index 6 "💾 START: backup run"
- assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1"
+ assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com"
assert_line --index 8 "################################################################################"
- assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/home/user${RESET}"
- assert_line --index 10 "❌ ERROR: missing host for testpc1"
+ assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/home/user${RESET}"
+ assert_line --index 10 "❌ ERROR: missing host for testpc1.example.com"
}
# bats test_tags=backup:info
"backup_name": "backup",
"backup_count": 15,
"machines": {
- "testpc1": {
+ "testpc1.example.com": {
"remote_user": "testuser",
"host": "remotehost",
"pathes": ["/home/user"]
assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup"
assert_line --index 6 "💾 START: backup run"
- assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1"
+ assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com"
assert_line --index 8 "################################################################################"
- assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/home/user${RESET}"
- assert_line --index 10 "❌ ERROR: missing port for testpc1"
+ assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/home/user${RESET}"
+ assert_line --index 10 "❌ ERROR: missing port for testpc1.example.com"
}
# bats test_tags=backup:info
assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup"
assert_line --index 6 "💾 START: backup run"
- assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1"
+ assert_line --index 7 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/testpc1.example.com"
assert_line --index 8 "################################################################################"
- assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/etc${RESET}"
- assert_line --index 10 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; excludes /home/user/.cache /home/user/.local"
+ assert_line --index 9 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; path ${YELLOW}/etc${RESET}"
+ assert_line --index 10 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1.example.com${RESET}; excludes /home/user/.cache /home/user/.local"
assert_line --index 11 "################################################################################"
assert_line --partial "✅ SUCCESS: backup"
}
assert_equal "$(awk 'NR==10 {print; exit}' "$RSYNC_LOG")" "--exclude=/home/user/.local"
assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "--rsh=\"ssh -p 22\""
assert_equal "$(awk 'NR==12 {print; exit}' "$RSYNC_LOG")" "backupuser@www.example.com:/etc"
- assert_equal "$(awk 'NR==13 {print; exit}' "$RSYNC_LOG")" "build/test/2000-01-01_01_backup/testpc1"
+ assert_equal "$(awk 'NR==13 {print; exit}' "$RSYNC_LOG")" "build/test/2000-01-01_01_backup/testpc1.example.com"
}
assert_failure
assert_line --index 0 "⭐ START: backup"
- assert_line --partial "❌ ERROR: could not backup testpc1 with path /etc"
+ assert_line --partial "❌ ERROR: could not backup testpc1.example.com with path /etc"
}
# bats test_tags=backup:info,backup:cleanup