Improve database backup reliability and error handling

Enhance pg_dump backup command with --clean, --if-exists, and --inserts flags for improved reliability and compatibility, and update error logging for failed backups.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 42d8028a-fa71-4ec2-938c-e43eedf7df01
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/42d8028a-fa71-4ec2-938c-e43eedf7df01/B8lcojv
This commit is contained in:
marco370 2025-10-17 08:38:07 +00:00
parent 4693b782cb
commit 2f0831b81e
2 changed files with 3 additions and 6 deletions

View File

@ -27,10 +27,6 @@ externalPort = 3000
localPort = 42175
externalPort = 3002
[[ports]]
localPort = 42403
externalPort = 3003
[env]
PORT = "5000"

5
deploy-to-gitlab.sh Executable file → Normal file
View File

@ -135,7 +135,8 @@ else
log_info "Creo backup: $BACKUP_FILE"
# Backup con pg_dump (include schema e dati)
if pg_dump "$DATABASE_URL" > "$BACKUP_FILE" 2>/dev/null; then
# Opzioni: --clean (DROP before CREATE), --if-exists (no error if not exists), --inserts (INSERT statements per compatibilità)
if pg_dump "$DATABASE_URL" --clean --if-exists --inserts > "$BACKUP_FILE"; then
# Comprimi backup
gzip "$BACKUP_FILE"
BACKUP_FILE="${BACKUP_FILE}.gz"
@ -147,7 +148,7 @@ else
log_info "Pulizia backup vecchi (mantengo ultimi 10)..."
ls -t $BACKUP_DIR/*.sql.gz 2>/dev/null | tail -n +11 | xargs rm -f 2>/dev/null || true
else
log_error "Backup database fallito!"
log_error "Backup database fallito! Verifica DATABASE_URL e permessi pg_dump"
exit 1
fi
fi