This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
gitgram-ai/gitgram/scripts/restore-database.sh
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

85 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# Database Restore Script
# This script restores a database backup
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
BACKUP_DIR="${BACKUP_DIR:-/var/backups/gitgram}"
# Load environment variables
if [ -f .env.production ]; then
export $(cat .env.production | grep -v '^#' | xargs)
fi
# Check if DATABASE_URL is set
if [ -z "$DATABASE_URL" ]; then
echo -e "${RED}❌ ERROR: DATABASE_URL is not set${NC}"
exit 1
fi
# Check if backup file is provided
if [ -z "$1" ]; then
echo -e "${YELLOW}Available backups:${NC}"
ls -lh "$BACKUP_DIR"/gitgram_backup_*.sql.gz 2>/dev/null || echo "No backups found"
echo ""
echo "Usage: $0 <backup_file>"
echo "Example: $0 gitgram_backup_20250101_120000.sql.gz"
exit 1
fi
BACKUP_FILE="$1"
# Check if backup file exists
if [ ! -f "$BACKUP_DIR/$BACKUP_FILE" ]; then
echo -e "${RED}❌ ERROR: Backup file not found: $BACKUP_DIR/$BACKUP_FILE${NC}"
exit 1
fi
# Confirmation prompt
echo -e "${YELLOW}⚠️ WARNING: This will restore the database from backup${NC}"
echo "Backup file: $BACKUP_FILE"
echo "Database: $DATABASE_URL"
echo ""
read -p "Are you sure you want to continue? (yes/no): " CONFIRM
if [ "$CONFIRM" != "yes" ]; then
echo -e "${YELLOW}Restore cancelled${NC}"
exit 0
fi
# Create a backup of current database before restore
echo -e "${YELLOW}📦 Creating safety backup of current database...${NC}"
SAFETY_BACKUP="gitgram_pre_restore_$(date +%Y%m%d_%H%M%S).sql.gz"
pg_dump "$DATABASE_URL" | gzip > "$BACKUP_DIR/$SAFETY_BACKUP"
echo -e "${GREEN}✅ Safety backup created: $SAFETY_BACKUP${NC}"
# Restore database
echo -e "${YELLOW}🔄 Restoring database...${NC}"
gunzip -c "$BACKUP_DIR/$BACKUP_FILE" | psql "$DATABASE_URL"
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ Database restored successfully${NC}"
else
echo -e "${RED}❌ Restore failed${NC}"
echo -e "${YELLOW}You can restore from safety backup: $SAFETY_BACKUP${NC}"
exit 1
fi
# Run migrations to ensure schema is up to date
echo -e "${YELLOW}🔄 Running migrations...${NC}"
cd "$(dirname "$0")/../backend"
npx prisma migrate deploy
echo ""
echo -e "${GREEN}✅ Restore process completed successfully!${NC}"
exit 0