Backup & Restore
GitWire includes built-in backup and restore scripts for disaster recovery.
Automated Backups
A daily cron job runs at 03:00 UTC on the production server:
bash
# /etc/cron.d/gitwire-backup
0 3 * * * root /opt/gitwire/scripts/backup.sh >> /var/log/gitwire-backup.log 2>&1What's Backed Up
| Component | Method | Size (typical) |
|---|---|---|
| PostgreSQL | pg_dump (custom format, compressed) | ~200KB |
| Redis | BGSAVE + RDB copy | ~50KB |
| Environment | .env + docker-compose.yml | ~2KB |
| Manifest | manifest.json with metadata | ~1KB |
Total: ~4.8MB (compressed)
Backups are stored at /opt/gitwire/backups/ and auto-pruned to keep the last 10.
Backup Script
bash
# Located at scripts/backup.sh
# Usage:
./scripts/backup.shOutput structure:
backups/20260523_030000/
├── gitwire_db.dump # pg_dump custom format
├── gitwire_redis.rdb # Redis RDB snapshot
├── .env # Environment variables
├── docker-compose.yml # Docker configuration
└── manifest.json # Backup metadatamanifest.json
json
{
"timestamp": "2026-05-23T03:00:00Z",
"version": "0.8.0",
"tables": 39,
"repos": 19,
"db_size": 199000,
"backup_size": "4.8M"
}Restore Script
bash
# Located at scripts/restore.sh
# Usage:
./scripts/restore.sh /opt/gitwire/backups/20260523_030000The restore script:
- Prompts for confirmation — shows what will be restored
- Drops and recreates the
gitops_hubdatabase - Restores from the pg_dump file
- Copies the Redis RDB snapshot
- Restarts all GitWire services
- Verifies health endpoint
Data Loss
Restore drops the existing database. Make a fresh backup before restoring if you want to preserve current data.
Manual Backup
bash
# On the production server
ssh [email protected]
cd /opt/gitwire
./scripts/backup.shOffsite Backup
Copy the latest backup to your local machine:
bash
# From your local machine
scp -r [email protected]:/opt/gitwire/backups/$(ssh [email protected] 'ls -t /opt/gitwire/backups/ | head -1') ./backups/Database Migrations
Migrations run separately via the migration script:
bash
# Apply pending migrations
node scripts/migrate.jsMigrations are not included in backups — they're version-controlled in packages/web/db/migrations/. After restoring, run migrations if the backup is from an older version.