ids.alfacom.it/deployment/cleanup_database.sh
marco370 661e945f57 Implement automatic database cleanup and schema updates
Adds scripts for automatic database log cleanup, schema migration application, and cron job setup. Modifies the update script to apply SQL migrations before pushing Drizzle schema.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 9a659f15-d68a-4b7d-99f8-3eccc59afebe
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/4LjHWWz
2025-11-21 16:49:13 +00:00

47 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# =============================================================================
# IDS - Pulizia Database Automatica
# =============================================================================
# Esegui giornalmente via cron per mantenere database pulito
# Esempio cron: 0 3 * * * /opt/ids/deployment/cleanup_database.sh
# =============================================================================
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
IDS_DIR="/opt/ids"
# Carica variabili ambiente
if [ -f "$IDS_DIR/.env" ]; then
source "$IDS_DIR/.env"
fi
# Verifica DATABASE_URL
if [ -z "$DATABASE_URL" ]; then
echo "[ERROR] DATABASE_URL non impostato"
exit 1
fi
echo "=========================================="
echo "IDS - Pulizia Database $(date)"
echo "=========================================="
# Dimensione database PRIMA della pulizia
echo ""
echo "📊 Dimensione database PRIMA:"
psql "$DATABASE_URL" -c "SELECT pg_size_pretty(pg_database_size(current_database()));"
# Esegui pulizia
echo ""
echo "🧹 Eliminazione log vecchi (>7 giorni)..."
psql "$DATABASE_URL" -f "$IDS_DIR/database-schema/cleanup_old_logs.sql"
# Dimensione database DOPO la pulizia
echo ""
echo "📊 Dimensione database DOPO:"
psql "$DATABASE_URL" -c "SELECT pg_size_pretty(pg_database_size(current_database()));"
echo ""
echo "✅ Pulizia completata - $(date)"
echo "=========================================="