Operations manual

Reference · 03

Backup and restore

Backups are manual-only and S3-only. There is no backup timer and no local archive, so the VPS disk is never used as backup storage.

ReferenceBackupRecoveryReviewed November 2026

What is backed up

ItemArchiveMethod
PostgreSQLdb-<timestamp>.sql.gzpg_dump --clean --if-exists through gzip.
SQLite (local)db-<timestamp>.sql.gzSQLite backup API, then gzip.
Local media (including private)media-<timestamp>.tar.gzTar archive of media/.
Public S3 mediamedia-<timestamp>.tar.gzDownloaded into media/s3-media/ inside the archive.
StaticNot archivedRebuilt by collectstatic.
DocumentationIn release packageStatic HTML shipped with the application.

The database dump and media archive are staged in a temporary directory, uploaded to s3://BACKUP_S3_BUCKET/backups/<timestamp>/, then removed from the VPS. Nothing is written to a persistent local backup directory.

Manual backup

# Create and harden the private bucket once the IAM policy allows it
python manage.py setup_backup_bucket

# Run a backup on demand
python manage.py create_backup --confirm --keep 14

# Or use Dashboard -> Backups -> Create backup now

BACKUP_S3_BUCKET is required. If it is missing the command fails closed; there is no local-disk fallback. The bucket is separate from the public media/static bucket and has public access blocked, AES256 encryption and versioning enabled. The dashboard action and the command are the only backup triggers; no systemd timer or cron job is installed.

Private bucket and IAM

Attach deploy/aws-backup-policy.json to the application IAM user alongside the existing media/static policy. It grants bucket creation and hardening, plus object access only under the backups/ prefix. Remove s3:CreateBucket after the bucket exists if you want to tighten the policy further.

BACKUP_S3_BUCKET=perfumz-backups-708076751352
BACKUP_S3_PREFIX=backups
BACKUP_S3_REGION=us-east-2
BACKUP_S3_SSE=AES256
BACKUP_S3_KMS_KEY_ID=
BACKUP_KEEP=14

Never point BACKUP_S3_BUCKET at the public media/static bucket. The command rejects that configuration.

Restore PostgreSQL

Do not restore over the live database under traffic. Stop the application, keep the damaged database for investigation, and restore into a separate database first.

sudo systemctl stop perfumz
aws s3 cp s3://<backup-bucket>/backups/<timestamp>/db-<timestamp>.sql.gz - \
  | gunzip -c | sudo -u postgres psql perfumz_restore
sudo -u postgres psql perfumz_restore -c 'select count(*) from commerce_order;'
sudo systemctl start perfumz

After switching, run migrate only if the restored backup predates the current schema, and run check --deploy before opening traffic.

Restore media

sudo systemctl stop perfumz
aws s3 cp s3://<backup-bucket>/backups/<timestamp>/media-<timestamp>.tar.gz /tmp/
tar -xzf /tmp/media-<timestamp>.tar.gz \
  -C /srv/perfumz
sudo chown -R perfumz:perfumz /srv/perfumz/media
sudo chmod -R a+rX /srv/perfumz/media
sudo systemctl start perfumz

The archive includes local private media under media/private/ and public S3 media under media/s3-media/. Restore public S3 objects to the media bucket with sync_media_to_s3 or an S3 copy after extracting; private files stay on local disk.

Restore drill

  • Choose an archive older than the current release.
  • Restore it into a separate database and media directory.
  • Run migrations, checks and a read-only smoke test.
  • Confirm an order, a customer, a product and an affiliate record are present.
  • Record the restore duration and any missing dependency.
  • Delete the drill database and media copy when finished.
Perfumz Operations Manual · English reference · Reviewed November 2026