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)
84 lines
2.4 KiB
Bash
Executable File
84 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# =============================================================================
|
|
# Aurora Database Restore Script
|
|
# =============================================================================
|
|
# Restores the database from a SQL backup file.
|
|
# Automatically creates a safety backup before overwriting.
|
|
#
|
|
# Usage: ./db-restore.sh <path-to-backup.sql>
|
|
# =============================================================================
|
|
|
|
set -e
|
|
|
|
# Load environment variables
|
|
if [ -f .env ]; then
|
|
set -a
|
|
source .env
|
|
set +a
|
|
fi
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# Colors
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m'
|
|
|
|
if [ -z "$1" ]; then
|
|
echo -e "${RED}Error: Please specify the backup file to restore.${NC}"
|
|
echo "Usage: ./db-restore.sh <path-to-sql-file>"
|
|
echo ""
|
|
echo "Available backups:"
|
|
ls -lh shared/db/backups/*.sql 2>/dev/null || echo " (No backups found in shared/db/backups)"
|
|
exit 1
|
|
fi
|
|
|
|
BACKUP_FILE="$1"
|
|
|
|
if [ ! -f "$BACKUP_FILE" ]; then
|
|
echo -e "${RED}Error: File not found: $BACKUP_FILE${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Validate the backup file looks like SQL
|
|
if ! head -1 "$BACKUP_FILE" | grep -qiE '(^--|^SET|^CREATE|^INSERT|^\\\\connect|^pg_dump)'; then
|
|
echo -e "${YELLOW}⚠️ Warning: File does not appear to be a SQL dump.${NC}"
|
|
read -p "Continue anyway? (y/N): " -n 1 -r
|
|
echo ""
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
echo "Operation cancelled."
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
echo -e "${YELLOW}⚠️ WARNING: This will OVERWRITE the current database!${NC}"
|
|
echo -e "Target Database: ${DB_NAME:-auroradev}"
|
|
echo -e "Backup File: $BACKUP_FILE"
|
|
echo -e "File Size: $(du -h "$BACKUP_FILE" | cut -f1)"
|
|
echo ""
|
|
read -p "Are you sure you want to proceed? (y/N): " -n 1 -r
|
|
echo ""
|
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
if ! docker ps | grep -q aurora_db; then
|
|
echo -e "${RED}Error: Database container (aurora_db) is not running!${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Create a safety backup before restoring
|
|
echo -e "${YELLOW}💾 Creating safety backup before restore...${NC}"
|
|
bash "$SCRIPT_DIR/db-backup.sh" || {
|
|
echo -e "${RED}⚠️ Safety backup failed. Aborting restore.${NC}"
|
|
exit 1
|
|
}
|
|
|
|
echo -e "${YELLOW}♻️ Restoring database...${NC}"
|
|
cat "$BACKUP_FILE" | docker exec -i aurora_db psql -U "${DB_USER:-auroradev}" -d "${DB_NAME:-auroradev}"
|
|
|
|
echo -e " ${GREEN}✓${NC} Restore complete!"
|
|
else
|
|
echo "Operation cancelled."
|
|
exit 0
|
|
fi
|