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

# Backup & Restore

## Physical Snapshot

```bash
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

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

Verify:

```sql
SELECT last_archived_wal, last_archived_time, archived_count, failed_count
FROM pg_stat_archiver;
```

## pgBackRest

```bash
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:

```cron
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

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

## Logical Backup

```bash
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
```
