mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-09-28 07:07:17 +02:00
tools.func: complete a stale/partial backup manifest instead of trusting it as-is
This commit is contained in:
+15
-15
@@ -1292,14 +1292,17 @@ create_temp_dir() {
|
|||||||
# - Copies each given file/directory into a persistent store at
|
# - Copies each given file/directory into a persistent store at
|
||||||
# /opt/<NSAPP>.backup, mirroring its absolute path inside the store, and
|
# /opt/<NSAPP>.backup, mirroring its absolute path inside the store, and
|
||||||
# records it in a manifest so restore_backup needs no arguments.
|
# records it in a manifest so restore_backup needs no arguments.
|
||||||
# - Idempotent: if a store from a previous (failed) run already exists, it is
|
# - Idempotent per path: a path already recorded in the manifest (from this
|
||||||
# left untouched and no new backup is taken. This keeps the last-known-good
|
# run or a previous failed one) is left untouched, keeping the
|
||||||
# data instead of overwriting it with now-partially-updated data on retry.
|
# last-known-good copy instead of overwriting it with now-partially-updated
|
||||||
|
# data on retry. Any requested path NOT yet in the manifest is backed up
|
||||||
|
# now and appended - so a manifest left incomplete by an interrupted prior
|
||||||
|
# run gets completed instead of silently missing paths on restore.
|
||||||
# - Missing source paths are skipped with a warning (not fatal).
|
# - Missing source paths are skipped with a warning (not fatal).
|
||||||
# - Aborts the update on copy failure: if any file/dir cannot be backed up,
|
# - Aborts the update on copy failure: if any file/dir cannot be backed up,
|
||||||
# the half-written store is removed and the script exits, so the update
|
# the script exits before the update runs against unprotected data (the
|
||||||
# never runs against unprotected data (and a retry re-attempts a clean
|
# paths already recorded are left in place, so a retry only redoes the one
|
||||||
# backup rather than skipping it).
|
# that failed).
|
||||||
#
|
#
|
||||||
# restore_backup
|
# restore_backup
|
||||||
# - Copies every path recorded in the manifest back to its origin (replacing
|
# - Copies every path recorded in the manifest back to its origin (replacing
|
||||||
@@ -1318,19 +1321,17 @@ create_backup() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -f "$manifest" ]]; then
|
if ! mkdir -p "$store" || ! touch "$manifest"; then
|
||||||
msg_ok "Existing backup found at ${store}, skipping backup"
|
msg_error "Backup failed: could not create store at ${store} - aborting update"
|
||||||
return 0
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
msg_info "Backing up data"
|
msg_info "Backing up data"
|
||||||
if ! mkdir -p "$store" || ! : >"$manifest"; then
|
|
||||||
msg_error "Backup failed: could not create store at ${store} - aborting update"
|
|
||||||
rm -rf "$store"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
for path in "$@"; do
|
for path in "$@"; do
|
||||||
path="${path%/}"
|
path="${path%/}"
|
||||||
|
if grep -qxF "$path" "$manifest" 2>/dev/null; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
if [[ ! -e "$path" ]]; then
|
if [[ ! -e "$path" ]]; then
|
||||||
msg_warn "Skipping backup of '${path}' (not found)"
|
msg_warn "Skipping backup of '${path}' (not found)"
|
||||||
continue
|
continue
|
||||||
@@ -1338,7 +1339,6 @@ create_backup() {
|
|||||||
dest="${store}/files${path}"
|
dest="${store}/files${path}"
|
||||||
if ! mkdir -p "$(dirname "$dest")" || ! cp -a "$path" "$dest"; then
|
if ! mkdir -p "$(dirname "$dest")" || ! cp -a "$path" "$dest"; then
|
||||||
msg_error "Backup of '${path}' failed - aborting update"
|
msg_error "Backup of '${path}' failed - aborting update"
|
||||||
rm -rf "$store"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$path" >>"$manifest"
|
echo "$path" >>"$manifest"
|
||||||
|
|||||||
Reference in New Issue
Block a user