# Backup Restore Guide

This document describes the exact restore flow for Aesthetic HUB backups.

## 1) Prerequisites

- Correct `.env` values for DB and backup storage.
- Access to off-site S3-compatible backup bucket.
- `mysql` and `mysqldump` installed on the restore host.

## 2) Download latest backup dump

The backup job stores DB dumps under:

- `aesthetic-hub/daily/db/`
- `aesthetic-hub/weekly/db/`
- `aesthetic-hub/monthly/db/`

Download the target file (example uses AWS CLI-compatible command):

```bash
aws s3 cp "s3://<bucket>/aesthetic-hub/daily/db/db_YYYYMMDD_HHMMSS.sql.gz" "./db_restore.sql.gz" --endpoint-url="<endpoint-if-needed>"
```

## 3) Restore database (staging recommended first)

```bash
gunzip -c ./db_restore.sql.gz | mysql -h127.0.0.1 -P3306 -u<db_user> -p<db_name>
```

## 4) Restore uploaded files

Uploads are synced under:

- `aesthetic-hub/uploads/`

Sync back to `storage/app/public`:

```bash
aws s3 sync "s3://<bucket>/aesthetic-hub/uploads/" "./storage/app/public/" --endpoint-url="<endpoint-if-needed>"
```

Then ensure symlink exists:

```bash
php artisan storage:link
```

## 5) Verification checklist

- [ ] DB restore command completed without SQL errors.
- [ ] `php artisan about` runs without DB connection errors.
- [ ] Key tables have expected row counts (users, patients, appointments, invoices).
- [ ] Uploaded files are present in `storage/app/public`.
- [ ] Can open a sample patient photo/document.
- [ ] Admin login works in restored environment.
- [ ] Dashboard loads without server errors.
- [ ] Run smoke tests: `php artisan test`.

## 6) Test restore policy

Run a test restore on staging before any production migration batch.  
Record date, backup filename, and verifier name in release notes.
