Backup & Restore
Data Overview
Section titled “Data Overview”Glean data is stored in the following locations:
| Data Type | Storage Location | Importance |
|---|---|---|
| Database | PostgreSQL (postgres_data volume) | Critical |
| Cache | Redis (redis_data volume) | Optional |
| Logs | glean_logs volume | Optional |
| Vector Data | Milvus volumes (full version) | Important |
Database Backup
Section titled “Database Backup”Manual Backup
Section titled “Manual Backup”# Backup PostgreSQL databasedocker exec glean-postgres pg_dump -U glean glean | gzip > glean_db_$(date +%Y%m%d_%H%M%S).sql.gzAutomated Backup Script
Section titled “Automated Backup Script”Create backup script backup-glean.sh:
#!/bin/bash
BACKUP_DIR="$HOME/glean-backups"DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p "$BACKUP_DIR"
# Backup PostgreSQLdocker exec glean-postgres pg_dump -U glean glean | gzip > "$BACKUP_DIR/glean_db_$DATE.sql.gz"
# Backup PostgreSQL data volumedocker run --rm \ -v glean_postgres_data:/data \ -v "$BACKUP_DIR":/backup \ alpine tar czf /backup/postgres_data_$DATE.tar.gz -C /data .
# Backup Redis data volumedocker run --rm \ -v glean_redis_data:/data \ -v "$BACKUP_DIR":/backup \ alpine tar czf /backup/redis_data_$DATE.tar.gz -C /data .
# Clean up backups older than 7 daysfind "$BACKUP_DIR" -name "*.gz" -mtime +7 -delete
echo "Backup completed: $BACKUP_DIR"Set execute permission and run:
chmod +x backup-glean.sh./backup-glean.shScheduled Backups
Section titled “Scheduled Backups”Set up daily backups with cron:
# Edit crontabcrontab -e
# Add daily backup at 2 AM0 2 * * * /path/to/backup-glean.shDatabase Restore
Section titled “Database Restore”Restore from SQL Backup
Section titled “Restore from SQL Backup”# Stop servicesdocker compose down
# Start databasedocker compose up -d postgres
# Wait for database to be readysleep 10
# Restore datagunzip -c glean_db_20250101_020000.sql.gz | docker exec -i glean-postgres psql -U glean -d glean
# Start all servicesdocker compose up -dRestore from Volume Backup
Section titled “Restore from Volume Backup”# Stop servicesdocker compose down
# Remove old volumedocker volume rm glean_postgres_data
# Create new volumedocker volume create glean_postgres_data
# Restore datadocker run --rm \ -v glean_postgres_data:/data \ -v "$HOME/glean-backups":/backup \ alpine tar xzf /backup/postgres_data_20250101_020000.tar.gz -C /data
# Start servicesdocker compose up -dFull Backup (with Milvus)
Section titled “Full Backup (with Milvus)”Full version also needs to backup Milvus data:
#!/bin/bash
BACKUP_DIR="$HOME/glean-backups"DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p "$BACKUP_DIR"
# Backup PostgreSQLdocker exec glean-postgres pg_dump -U glean glean | gzip > "$BACKUP_DIR/glean_db_$DATE.sql.gz"
# Backup all data volumesfor volume in postgres_data redis_data milvus_etcd_data milvus_minio_data milvus_data; do docker run --rm \ -v glean_${volume}:/data \ -v "$BACKUP_DIR":/backup \ alpine tar czf /backup/${volume}_$DATE.tar.gz -C /data .done
echo "Full backup completed: $BACKUP_DIR"Migrating to New Server
Section titled “Migrating to New Server”Export Data
Section titled “Export Data”On the old server:
# Backup databasedocker exec glean-postgres pg_dump -U glean glean | gzip > glean_backup.sql.gz
# Export OPML (optional, user-level)# Export via Web interfaceImport Data
Section titled “Import Data”On the new server:
# Deploy Gleancurl -fsSL https://raw.githubusercontent.com/LeslieLeung/glean/main/docker-compose.yml -o docker-compose.ymldocker compose up -d
# Wait for database to be readysleep 30
# Restore datagunzip -c glean_backup.sql.gz | docker exec -i glean-postgres psql -U glean -d glean
# Restart servicesdocker compose restartBackup Strategy Recommendations
Section titled “Backup Strategy Recommendations”| Strategy | Frequency | Retention | Description |
|---|---|---|---|
| Daily Backup | Daily | 7 days | SQL backup |
| Weekly Backup | Weekly | 4 weeks | Full volume backup |
| Monthly Backup | Monthly | 12 months | Archive backup |
Verifying Backups
Section titled “Verifying Backups”Regularly verify backup integrity:
# Check backup filesgunzip -t glean_db_*.sql.gz
# Restore in test environment to verifydocker compose -f docker-compose.test.yml up -d# Restore and verify dataNext Steps
Section titled “Next Steps”- Update Guide - Update Glean version
- Troubleshooting - Common issue resolution