BACKUP & RESTORE
GalaxDB supports online backup and restore via SQL commands. Backups are consistent point-in-time snapshots that include all data, indexes, and version tags.
BACKUP TO
SQL
BACKUP TO '/path/to/backup/directory';Creates a consistent backup of the entire database to the specified directory. The backup is taken online — reads and writes continue during the backup. The backup directory is created if it doesn't exist.
SQL
-- Backup to a local directory
BACKUP TO '/var/backups/galaxdb/2024-01-15';
-- Backup to a mounted network share
BACKUP TO '/mnt/nas/galaxdb-backups/daily';Tip
Include a timestamp in the backup path to keep multiple backups:
BACKUP TO '/backups/galaxdb-2024-01-15T03:00:00'RESTORE FROM
SQL
RESTORE FROM '/path/to/backup/directory';Restores the database from a backup directory. The current database state is replaced with the backup. All data, indexes, and version tags from the backup are restored.
Danger
RESTORE FROM replaces the current database state. Ensure you have a backup of the current state before restoring, or that you intend to discard current data.
SQL
-- Restore from a backup
RESTORE FROM '/var/backups/galaxdb/2024-01-15';Examples
Scheduled backup script
bash
#!/bin/bash
# Daily backup script
DATE=$(date +%Y-%m-%d)
BACKUP_DIR="/var/backups/galaxdb/$DATE"
psql "host=localhost port=5433 dbname=galaxdb sslmode=disable" \
-c "BACKUP TO '$BACKUP_DIR'"
echo "Backup completed: $BACKUP_DIR"
# Keep only last 7 days
find /var/backups/galaxdb -maxdepth 1 -type d -mtime +7 -exec rm -rf {} +Python backup
Python
import galaxdb
from datetime import datetime
db = galaxdb.Database("./data")
# Create timestamped backup
ts = datetime.now().strftime("%Y-%m-%dT%H-%M-%S")
backup_path = f"/var/backups/galaxdb/{ts}"
result = db.execute(f"BACKUP TO '{backup_path}'")
print(f"Backup result: {result}")
# Restore from backup
result = db.execute(f"RESTORE FROM '{backup_path}'")
print(f"Restore result: {result}")Disaster recovery workflow
bash
# 1. Stop writes (optional, for consistency)
# 2. Create backup
psql "host=localhost port=5433 dbname=galaxdb sslmode=disable" \
-c "BACKUP TO '/backups/pre-migration'"
# 3. Run migration
psql "host=localhost port=5433 dbname=galaxdb sslmode=disable" \
-f migration.sql
# 4. If migration fails, restore
psql "host=localhost port=5433 dbname=galaxdb sslmode=disable" \
-c "RESTORE FROM '/backups/pre-migration'"