Backup
Back up and restore your Stasis instance
Backup
Regular backups protect you from data loss. This page explains what to back up and how.
What to Back Up
Stasis stores data in two places:
- PostgreSQL database — user accounts, repository metadata, SSH keys, tokens
- Repository files — the actual git repositories on disk
You need to back up both.
Backing Up PostgreSQL
Using pg_dump
# Full backup
docker compose exec postgres pg_dump -U stasis stasis > backup-$(date +%Y%m%d).sql
# Compressed backup
docker compose exec postgres pg_dump -U stasis stasis | gzip > backup-$(date +%Y%m%d).sql.gzAutomated Daily Backup
Create a backup script at scripts/backup-db.sh:
#!/bin/bash
BACKUP_DIR="/path/to/backups"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
docker compose exec -T postgres pg_dump -U stasis stasis | gzip > "$BACKUP_DIR/db_$DATE.sql.gz"
# Keep only last 30 days
find $BACKUP_DIR -name "db_*.sql.gz" -mtime +30 -deleteMake it executable and add to cron:
chmod +x scripts/backup-db.sh
crontab -e
# Add: 0 2 * * * /path/to/stasis/scripts/backup-db.shBacking Up Repositories
The git repositories are stored in a Docker volume. Back them up:
# Find the volume path
docker volume inspect stasis_repo_data
# Copy the volume data
docker run --rm -v stasis_repo_data:/data -v $(pwd)/backups:/backup alpine tar czf /backup/repos-$(date +%Y%m%d).tar.gz /dataOr if you're using a bind mount:
# Back up the repos directory
tar czf repos-$(date +%Y%m%d).tar.gz /path/to/reposAutomated Backup Script
Create scripts/backup.sh:
#!/bin/bash
set -e
BACKUP_DIR="/path/to/backups"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
echo "Backing up database..."
docker compose exec -T postgres pg_dump -U stasis stasis | gzip > "$BACKUP_DIR/db_$DATE.sql.gz"
echo "Backing up repositories..."
docker run --rm -v stasis_repo_data:/data -v $BACKUP_DIR:/backup alpine tar czf /backup/repos_$DATE.tar.gz /data
echo "Backup complete: $BACKUP_DIR"
ls -lh $BACKUP_DIR/*_$DATE.*
# Clean up old backups (keep 30 days)
find $BACKUP_DIR -name "*.gz" -mtime +30 -deleteRestoring from Backup
Restore Database
# Stop the API server
docker compose stop api
# Restore the database
gunzip < backup-20240101.sql.gz | docker compose exec -T postgres psql -U stasis stasis
# Start the API server
docker compose start apiRestore Repositories
# Stop all services
docker compose down
# Restore the volume
docker run --rm -v stasis_repo_data:/data -v $(pwd)/backups:/backup alpine sh -c "cd /data && tar xzf /backup/repos_20240101.tar.gz --strip-components=1"
# Start services
docker compose up -dTesting Backups
Regularly test your backups by restoring them to a test environment:
- Set up a test environment with Docker Compose
- Restore the backup
- Verify you can log in and access repositories
- Verify git operations work