# Backup and restore

## Scope and policy

Back up the relational database, private object storage, shared public assets if any,
the production `.env`, and the encryption key in separate encrypted secret storage.
Recommended minimum: nightly database backup, object-store versioning, 35 daily and
12 monthly copies, and an off-site immutable copy. Define retention with applicable
education, privacy, and finance rules.

## MySQL backup

```bash
mysqldump --single-transaction --routines --triggers --hex-blob \
  --host="$DB_HOST" --user="$DB_USERNAME" --password \
  "$DB_DATABASE" | gzip > "university-erp-$(date -u +%Y%m%dT%H%M%SZ).sql.gz"
sha256sum university-erp-*.sql.gz > SHASUMS256.txt
```

Do not put database passwords on the command line in automation; use a protected
client option file or secret-injected credential.

## Restore rehearsal

1. Provision an isolated database and private bucket.
2. Verify the checksum, decompress, and import the dump.
3. Restore the object snapshot with original keys.
4. restore the matching `APP_KEY` and configuration.
5. Run `php artisan migrate:status`, `/ready`, smoke tests, document downloads,
   encrypted-field reads, and ledger/report reconciliation.
6. Record restore duration, recovery point, evidence, and defects; destroy the
   rehearsal environment securely.

Never test restores over production. A backup is not accepted until a restore has
been demonstrated.
