Backup & Restore
Protecting your knowledge graph data.
What Gets Backed Up
| Component | Contains | Backup Method |
|---|---|---|
| PostgreSQL | Concepts, relationships, users, config | pg_dump |
| Garage | Original documents | S3-compatible tools |
Quick Backup
Creates a timestamped SQL dump in the backups directory.
Backup Locations
Default backup location: ./backups/
Manual Database Backup
# Backup to file
docker exec kg-postgres pg_dump -U admin -d knowledge_graph > backup.sql
# Compressed
docker exec kg-postgres pg_dump -U admin -d knowledge_graph | gzip > backup.sql.gz
Restore
Or manually:
# Drop and recreate database
docker exec -i kg-postgres psql -U admin -c "DROP DATABASE IF EXISTS knowledge_graph;"
docker exec -i kg-postgres psql -U admin -c "CREATE DATABASE knowledge_graph;"
# Restore
docker exec -i kg-postgres psql -U admin -d knowledge_graph < backup.sql
Garage (Document Storage) Backup
Garage uses S3-compatible storage. Back up using standard S3 tools:
# Using AWS CLI (configured for Garage)
aws --endpoint-url http://localhost:3900 s3 sync s3://kg-storage ./garage-backup/
# Using rclone
rclone sync garage:kg-storage ./garage-backup/
Or copy the Garage data directory:
Automated Backups
Set up a cron job for regular backups:
# Edit crontab
crontab -e
# Add daily backup at 2 AM
0 2 * * * cd /path/to/knowledge-graph-system && ./operator.sh backup
Backup Retention
Clean up old backups periodically:
Disaster Recovery
Full recovery procedure:
-
Fresh installation:
-
Stop services:
-
Restore database:
-
Restore Garage data:
-
Start services:
-
Verify:
Testing Backups
Regularly verify backups work:
# Create test environment
docker run -d --name backup-test -e POSTGRES_PASSWORD=test postgres:16
# Restore to test
docker exec -i backup-test psql -U postgres < backup.sql
# Verify
docker exec backup-test psql -U postgres -d knowledge_graph -c "SELECT COUNT(*) FROM concepts;"
# Cleanup
docker rm -f backup-test