Backup & Restore¶
What to Backup¶
- Metadata - PostgreSQL database
- Data - Object storage files
- Configuration - Settings and secrets
Metadata Backup¶
PostgreSQL¶
# Backup
pg_dump -h localhost -U hafiz hafiz > hafiz-backup-$(date +%Y%m%d).sql
# Restore
psql -h localhost -U hafiz hafiz < hafiz-backup-20240101.sql
Kubernetes CronJob¶
apiVersion: batch/v1
kind: CronJob
metadata:
name: hafiz-backup
spec:
schedule: "0 2 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: backup
image: postgres:15
command:
- pg_dump
- -h
- postgres
- -U
- hafiz
volumeMounts:
- name: backup
mountPath: /backup
Data Backup¶
Filesystem¶
# Backup
tar czf hafiz-data-$(date +%Y%m%d).tar.gz /data
# Restore
tar xzf hafiz-data-20240101.tar.gz -C /
Volume Snapshots¶
Use cloud provider volume snapshots for faster recovery.
Disaster Recovery¶
- Restore PostgreSQL from backup
- Restore data files
- Start Hafiz
- Verify with health check