fix(backup): use stable run timestamp for db dump move #3

Merged
rhino merged 2 commits from fix/backup-dump-move-stable-timestamp into master 2026-04-25 12:20:15 +00:00
Showing only changes of commit a6bd4e2e87 - Show all commits

View File

@@ -150,8 +150,11 @@ cleanup_old_backups() {
done done
fi fi
} }
# Prepare dated backup directory # Prepare dated backup directory using a stable run timestamp.
DATED_DIR="$BACKUP_BASE/$(date_formatted)" # This prevents later steps from missing files if the minute changes while
# long archive operations are running.
RUN_STAMP="$(date_formatted)"
DATED_DIR="$BACKUP_BASE/$RUN_STAMP"
mkdir -p "$DATED_DIR" mkdir -p "$DATED_DIR"
wait_for_database_backups || exit 1 wait_for_database_backups || exit 1
@@ -188,7 +191,22 @@ log "Moving files from database dump to dated directory..."
#log "Files to move:" #log "Files to move:"
ls -1 "$BACKUP_BASE/databases"/* 2>/dev/null || true ls -1 "$BACKUP_BASE/databases"/* 2>/dev/null || true
log "Moving database dumps to dated directory..." log "Moving database dumps to dated directory..."
mv "$BACKUP_BASE/databases"/*_$(date_formatted)*.sql.gz "$DATED_DIR"/ 2>/dev/null || true
dump_moved=0
for dump_file in "$BACKUP_BASE/databases"/*_"$RUN_STAMP"*.sql.gz; do
[ -e "$dump_file" ] || break
if mv "$dump_file" "$DATED_DIR"/; then
dump_moved=$((dump_moved + 1))
else
err "Failed to move database dump $dump_file"
fi
done
if [ "$dump_moved" -eq 0 ]; then
log "No database dumps matched run timestamp $RUN_STAMP"
else
log "Moved $dump_moved database dump(s) to $DATED_DIR"
fi
cleanup_old_backups cleanup_old_backups