diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index d9de5145..7335ff93 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -50,12 +50,31 @@ jobs: export PNPM_CONFIG_ONLY_BUILT_DEPENDENCIES="@parcel/watcher,@swc/core,sharp" pnpm install --frozen-lockfile - # 5. [SAFETY] Database Backup & Migration - # TIP: Adjust this to your database (e.g., pg_dump for Postgres or cp for SQLite) + # 5. [SAFETY] Database Backup with Rotation (Keeps only last 5 backups) echo "Creating database backup..." - # Example for SQLite: - # cp prisma/dev.db prisma/backup_prior_to_deploy.db + BACKUP_DIR="/var/www/atom-nexst/backups" + mkdir -p "$BACKUP_DIR" + TIMESTAMP=$(date +%Y%m%d_%H%M%S) + BACKUP_FILE="$BACKUP_DIR/db_backup_$TIMESTAMP.sql" + + # ----------------- DATABASE CONFIGURATION ----------------- + # Read credentials directly from your .env file or environment if available, + # or customize these variables to match your system. + DB_USER="root" + DB_NAME="epicnext" + # ---------------------------------------------------------- + + # Create a secure, compressed backup using mysqldump + # Note: If your MySQL requires a password, add '-pYourPassword' (no space after -p) + # or configure a secure /home/user/.my.cnf file to read credentials automatically. + mysqldump -u "$DB_USER" "$DB_NAME" > "$BACKUP_FILE" + + echo "Rotating older backups (keeping only the 5 newest files)..." + # Lists backup files newest first, skips the first 5, and deletes any remaining older files + ls -dt "$BACKUP_DIR"/db_backup_*.sql | tail -n +6 | xargs -r rm + + # Apply versioned CMS migrations and generate the Prisma client safely pnpm db:migrate pnpm prisma:generate