๐พ Backups โ
Losing your database means losing all orders, customers, menu items, and settings. This page shows how to set up automatic backups so you never lose data.
๐ What to Back Up โ
| Data | Location | Priority |
|---|---|---|
| ๐๏ธ PostgreSQL database | pgdata Docker volume | Critical |
| ๐ผ๏ธ Uploaded images | uploads Docker volume | Important |
| ๐ Environment file | /home/kitchenasty/kitchenasty/.env | Important |
| ๐ณ Docker Compose file | docker-compose.prod.yml | Nice to have (in git) |
๐ Automatic Database Backups โ
๐ Create the Backup Script โ
sudo mkdir -p /opt/backups/kitchenasty
sudo chown kitchenasty:kitchenasty /opt/backups/kitchenasty
nano /home/kitchenasty/backup.shPaste:
#!/bin/bash
# KitchenAsty Database Backup Script
set -euo pipefail
BACKUP_DIR="/opt/backups/kitchenasty"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
KEEP_DAYS=30
echo "[$(date)] Starting backup..."
# Dump the database from the running PostgreSQL container
docker compose -f /home/kitchenasty/kitchenasty/docker-compose.prod.yml \
exec -T postgres pg_dump -U kitchenasty -Fc kitchenasty \
> "${BACKUP_DIR}/db_${TIMESTAMP}.dump"
# Back up uploaded images
tar -czf "${BACKUP_DIR}/uploads_${TIMESTAMP}.tar.gz" \
-C /var/lib/docker/volumes/ kitchenasty_uploads 2>/dev/null || true
# Back up environment file
cp /home/kitchenasty/kitchenasty/.env \
"${BACKUP_DIR}/env_${TIMESTAMP}.bak"
# Delete backups older than KEEP_DAYS
find "${BACKUP_DIR}" -type f -mtime +${KEEP_DAYS} -delete
echo "[$(date)] Backup complete: db_${TIMESTAMP}.dump"
echo "Backup size: $(du -sh ${BACKUP_DIR}/db_${TIMESTAMP}.dump | cut -f1)"Make it executable:
chmod +x /home/kitchenasty/backup.sh๐งช Test the Script โ
/home/kitchenasty/backup.shVerify the backup was created:
ls -lh /opt/backups/kitchenasty/โฐ Schedule Automatic Backups โ
Run the backup daily at 3:00 AM using cron:
crontab -eAdd this line:
0 3 * * * /home/kitchenasty/backup.sh >> /opt/backups/kitchenasty/backup.log 2>&1๐ Restoring from a Backup โ
If you ever need to restore:
# Stop the server (to prevent writes during restore)
docker compose -f docker-compose.prod.yml stop server admin storefront
# Restore the database
docker compose -f docker-compose.prod.yml exec -T postgres \
pg_restore -U kitchenasty -d kitchenasty --clean --if-exists \
< /opt/backups/kitchenasty/db_20260220_030000.dump
# Start everything again
docker compose -f docker-compose.prod.yml up -dReplace the filename with your actual backup file.
โ๏ธ Off-Site Backups โ
Local backups protect against accidental deletion, but not against server failure. Copy backups to an external location.
๐ Option 1: Rsync to Another Server โ
# Add to the backup script or as a separate cron job
rsync -az /opt/backups/kitchenasty/ user@backup-server:/backups/kitchenasty/โ๏ธ Option 2: Upload to S3 or Backblaze B2 โ
Install the AWS CLI or B2 CLI:
# For AWS S3
sudo apt install -y awscli
aws configure # Enter your access keys
# Add to backup script:
aws s3 sync /opt/backups/kitchenasty/ s3://your-bucket/kitchenasty-backups/# For Backblaze B2 (cheaper alternative)
pip install b2-sdk
b2 authorize-account YOUR_KEY_ID YOUR_APP_KEY
# Add to backup script:
b2 sync /opt/backups/kitchenasty/ b2://your-bucket/kitchenasty-backups/๐ง Option 3: Email Notification on Failure โ
Add this to the end of your backup script to get notified on failures:
# At the top of the script, add a trap
trap 'echo "Backup FAILED at $(date)" | mail -s "KitchenAsty Backup Failed" admin@yourdomain.com' ERRThis requires a mail utility (sudo apt install -y mailutils) and working SMTP configuration.
โ Backup Verification โ
Periodically verify that your backups are restorable. You can test on a separate server or locally:
# Create a temporary test database
docker exec kitchenasty-db createdb -U kitchenasty kitchenasty_test
# Restore into the test database
docker exec -i kitchenasty-db \
pg_restore -U kitchenasty -d kitchenasty_test --clean --if-exists \
< /opt/backups/kitchenasty/db_latest.dump
# Verify
docker exec kitchenasty-db psql -U kitchenasty -d kitchenasty_test \
-c "SELECT count(*) FROM orders;"
# Clean up
docker exec kitchenasty-db dropdb -U kitchenasty kitchenasty_testโก๏ธ Next Step โ
Continue to Maintenance for update procedures, monitoring, and troubleshooting.