forked from syntaxbullet/aurorabot
Scripts: - remote.sh: remove unused open_browser() function - deploy-remote.sh: add DB backup before deploy, --skip-backup flag, step numbering - db-backup.sh: fix macOS compat (xargs -r is GNU-only), use portable approach - db-restore.sh: add safety backup before restore, SQL file validation, file size display - logs.sh: default to no-follow with --tail=100, order-independent arg parsing - docker-cleanup.sh: add Docker health check, colored output - test-sequential.sh: exclude *.integration.test.ts by default, add --integration flag - simulate-ci.sh: pass --integration flag (has real DB) Tests: - db.test.ts: fix mock path from ./DrizzleClient to @shared/db/DrizzleClient - server.settings.test.ts: rewrite mocks for gameSettingsService (old config/saveConfig removed) - server.test.ts: add missing config.lootdrop and BotClient mocks, complete DrizzleClient chain - indexes.test.ts: rename to indexes.integration.test.ts (requires live DB) Config: - package.json: test script uses sequential runner, add test:ci and db:restore aliases - deploy.yml: use --integration flag in CI (has Postgres service)
65 lines
1.9 KiB
Bash
Executable File
65 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# =============================================================================
|
|
# Aurora Database Backup Script
|
|
# =============================================================================
|
|
# Creates a timestamped PostgreSQL backup and retains the last 10 backups.
|
|
#
|
|
# Usage: ./db-backup.sh
|
|
# =============================================================================
|
|
|
|
set -e
|
|
|
|
# Load environment variables
|
|
if [ -f .env ]; then
|
|
set -a
|
|
source .env
|
|
set +a
|
|
fi
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
BACKUP_DIR="$PROJECT_DIR/shared/db/backups"
|
|
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
|
BACKUP_FILE="$BACKUP_DIR/backup_$TIMESTAMP.sql"
|
|
|
|
# Colors
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m'
|
|
|
|
echo -e "${YELLOW}💾 Starting database backup...${NC}"
|
|
|
|
mkdir -p "$BACKUP_DIR"
|
|
|
|
if docker ps | grep -q aurora_db; then
|
|
# Try to dump the database
|
|
if docker exec aurora_db pg_dump -U "${DB_USER:-auroradev}" "${DB_NAME:-auroradev}" > "$BACKUP_FILE"; then
|
|
# Check if backup file is not empty
|
|
if [ -s "$BACKUP_FILE" ]; then
|
|
echo -e " ${GREEN}✓${NC} Backup successful!"
|
|
echo -e " 📂 File: $BACKUP_FILE"
|
|
echo -e " 📏 Size: $(du -h "$BACKUP_FILE" | cut -f1)"
|
|
|
|
# Keep only last 10 backups (cross-platform: works on macOS and Linux)
|
|
cd "$BACKUP_DIR"
|
|
OLD_BACKUPS=$(ls -t backup_*.sql 2>/dev/null | tail -n +11)
|
|
if [ -n "$OLD_BACKUPS" ]; then
|
|
echo "$OLD_BACKUPS" | xargs rm --
|
|
echo -e " ${GREEN}✓${NC} Pruned old backups"
|
|
fi
|
|
else
|
|
echo -e " ${RED}✗${NC} Backup created but empty. Something went wrong."
|
|
rm -f "$BACKUP_FILE"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo -e " ${RED}✗${NC} pg_dump failed."
|
|
rm -f "$BACKUP_FILE"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo -e " ${RED}✗${NC} Database container (aurora_db) is not running!"
|
|
exit 1
|
|
fi
|