Backup & Restore
Ontheia stores all persistent data in two Docker volumes. Regular backups are especially important before updates and in production environments.
Volume Overview
Section titled “Volume Overview”| Volume | Contents |
|---|---|
ontheia-db-data | PostgreSQL database (chats, agents, configuration, users) |
ontheia-sources | Namespace rule files (memory policies, configuration) |
Backup
Section titled “Backup”Database Backup (SQL Dump)
Section titled “Database Backup (SQL Dump)”docker exec ontheia-db pg_dump -U postgres ontheia > backup-$(date +%Y%m%d).sqlCompressed backup:
docker exec ontheia-db pg_dump -U postgres ontheia | gzip > backup-$(date +%Y%m%d).sql.gzNamespaces Volume
Section titled “Namespaces Volume”docker run --rm \ -v ontheia-sources:/data \ -v "$(pwd)/backups:/backup" \ alpine tar czf /backup./sources-$(date +%Y%m%d).tar.gz /dataFull Backup Script
Section titled “Full Backup Script”#!/bin/bashBACKUP_DIR="./backups"TIMESTAMP=$(date +%Y%m%d_%H%M%S)mkdir -p "$BACKUP_DIR"
# Databasedocker exec ontheia-db pg_dump -U postgres ontheia \ > "$BACKUP_DIR/ontheia-db-${TIMESTAMP}.sql"echo "✓ DB backup: $BACKUP_DIR/ontheia-db-${TIMESTAMP}.sql"
# Namespaces volumedocker run --rm \ -v ontheia-sources:/data \ -v "$(pwd)/backups:/backup" \ alpine tar czf "/backup/sources-${TIMESTAMP}.tar.gz" /dataecho "✓ Namespaces backup: $BACKUP_DIR/sources-${TIMESTAMP}.tar.gz"Recommendation: Cron Job
Section titled “Recommendation: Cron Job”Automated daily backup (Linux crontab):
# Every day at 03:000 3 * * * cd /opt/ontheia && bash scripts/backup.sh >> /var/log/ontheia-backup.log 2>&1Restore
Section titled “Restore”Restore Database
Section titled “Restore Database”Warning: This overwrites all current data in the database.
# Stop servicesdocker compose stop host webui
# Drop and recreate databasedocker exec -i ontheia-db psql -U postgres -c "DROP DATABASE IF EXISTS ontheia;"docker exec -i ontheia-db psql -U postgres -c "CREATE DATABASE ontheia;"docker exec -i ontheia-db psql -U postgres ontheia < backup-20240101.sql
# Re-run migrations (ensures schema consistency)docker compose up -d migratordocker compose wait migrator
# Start services againdocker compose up -dFrom a compressed backup:
gunzip -c backup-20240101.sql.gz | docker exec -i ontheia-db psql -U postgres ontheiaRestore Namespaces Volume
Section titled “Restore Namespaces Volume”docker run --rm \ -v ontheia-sources:/data \ -v "$(pwd)/backups:/backup" \ alpine sh -c "rm -rf /data/* && tar xzf /backup./sources-20240101.tar.gz -C / --strip-components=1"Backup Before Updates
Section titled “Backup Before Updates”The update.sh script automatically creates a backup before every update:
bash scripts/update.shBackups are stored in the ./backups/ directory.
- Back up your
.envfile: It contains all secrets (DB passwords, API keys, METRICS_TOKEN). Store it separately and encrypted. - Test your backups: Regularly perform a restore on a test instance to verify backups are valid.
- Off-site storage: Copy backups to external storage (S3, NFS, USB) — backups in the same directory do not protect against server loss.