# ZGZ Directus Restore

This project folder contains:

- Directus schema snapshot
- migration scripts
- uploaded files in `uploads/`
- optional extensions in `extensions/`

It does **not** contain the full PostgreSQL content database. To restore `https://clientes.deusens.com/zaragoza_backend` one-to-one, you need:

1. a PostgreSQL dump of `zgz_turismo`
2. the `uploads/` directory
3. optionally `extensions/` and `snapshots/`

## 1. Create a local database dump

Run locally:

```bash
bash scripts/backup_local_db.sh
```

This writes a timestamped `.sql` file to `backups/`.

## 2. Copy assets to the server

Copy these directories from the local project root to the server project root:

- `uploads/`
- `extensions/`
- `snapshots/`

Server project root example:

```text
/home/bitnami/htdocs/zaragoza_backend
```

After copying, fix ownership on the server:

```bash
cd /home/bitnami/htdocs/zaragoza_backend
sudo chown -R 1000:1000 uploads extensions snapshots
sudo chmod -R 775 uploads extensions snapshots
```

## 3. Back up the current server database

Run on the server:

```bash
sudo docker exec -t zgz_postgres pg_dump -U directus -d zgz_turismo > server_before_restore.sql
```

## 4. Restore the local dump on the server

Upload the generated `.sql` file to the server and run:

```bash
cd /home/bitnami/htdocs/zaragoza_backend
sudo bash scripts/restore_server_db.sh /absolute/path/to/zgz_turismo.sql
```

## 5. Verify the restore

Run on the server:

```bash
cd /home/bitnami/htdocs/zaragoza_backend
sudo bash scripts/verify_restore.sh
```

Expected results:

- Directus health returns `{"status":"ok"}`
- `languages`, `ui_translations`, `pois`, `routes`, `homepage_slides` have non-zero counts

## 6. If you have no SQL dump

You can still restore schema and files, but not full content:

```bash
sudo docker exec zgz_directus npx directus schema apply --yes /directus/snapshots/zgz_schema_snapshot.yaml
```

That restores collections/fields/relations, but **not** the actual records from PostgreSQL.
