# Operations

### Maintenance

When a new version is available, run:

```bash
./update.sh
```

The script performs the following steps:

1. Pulls the latest Docker images
2. Backs up the current volume data
3. Creates a database backup
4. Runs database migrations
5. Starts all Docker services
6. Cleans up unused Docker resources

### Backup Strategy

* Daily automated database backups via `pgbackups` service
* Volume data backup before updates
* Retention policies:
  * 7 days of daily backups
  * 4 weeks of weekly backups
  * 6 months of monthly backups

The specifics can be adjusted in the docker-config file.

### Backup Recovery

First, make sure there are no connections to the database by terminating all active connections:

```sql
SELECT * FROM pg_stat_activity WHERE pg_stat_activity.datname='DataSpace';
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'DataSpace';
```

Then drop and recreate the database:

```sql
DROP DATABASE "DataSpace";
CREATE DATABASE "DataSpace";
```

Finally, add the backup:

```bash
zcat "/opt/dataspace/Platform/volume/DataSpace_db_backup/<choose_your_backup>.sql.gz" | psql --host="database" --username="postgres" --dbname="DataSpace" -W
```

#### Manual Service Management

```bash
# Start services
docker compose --file docker-compose.yml --env-file .env up -d

# Stop services
docker compose down

# View logs
docker compose logs -f

# Restart specific service
docker compose restart api
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dataspace.ch/infrastructure/operations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
