mdcms/neuraldb-docs/pages/ops-backup.md

1.6 KiB

title sort section-id keywords description language
Backup & Restore 110 operations backup, restore, snapshot, WAL archiving, PITR, point-in-time recovery Backup and restore strategies for NeuralDB — snapshots, WAL archiving, and point-in-time recovery en

Backup & Restore

Physical Snapshot

pg_basebackup \
  --host=localhost --port=5432 --username=backup_user \
  --pgdata=/backups/neuraldb/$(date +%Y%m%d) \
  --wal-method=stream --checkpoint=fast --compress=lz4 --progress

WAL Archiving

wal_level = replica
archive_mode = on
archive_command = 'aws s3 cp %p s3://my-backups/neuraldb/wal/%f'
archive_timeout = 60

Verify:

SELECT last_archived_wal, last_archived_time, archived_count, failed_count
FROM pg_stat_archiver;

pgBackRest

sudo apt install pgbackrest
# Full backup
sudo -u postgres pgbackrest --stanza=neuraldb backup --type=full
# Differential
sudo -u postgres pgbackrest --stanza=neuraldb backup --type=diff

Cron schedule:

0 1 * * 0   postgres pgbackrest --stanza=neuraldb backup --type=full
0 1 * * 1-6 postgres pgbackrest --stanza=neuraldb backup --type=diff

Point-in-Time Recovery

systemctl stop neuraldb
pgbackrest --stanza=neuraldb restore \
  --target="2026-05-15 14:30:00+00" \
  --target-action=promote --delta
systemctl start neuraldb

Logical Backup

pg_dump -h localhost -U neuraldb mydb | lz4 | \
  aws s3 cp - s3://my-backups/neuraldb/logical-$(date +%Y%m%d).sql.lz4
pg_dump -Fc -h localhost -U neuraldb mydb > mydb-$(date +%Y%m%d).dump