# Maintenance

## Database backups&#x20;

The [cookiecutter-api](https://github.com/papaemmelab/cookiecutter-api) comes with some handy utilities to manage postgres backups, that you can inspect in your project code directory (`compose/production/postgres/maintenance`):

**1. To create a backup:**

```bash
docker-compose -f <environment>.yml (exec |run --rm) postgres backup
```

**2. To list/view current backups:**

```bash
docker-compose -f <environment>.yml (exec |run --rm) postgres backups
```

**3. To restore a backup:**

```bash
docker-compose -f <environment>.yml (exec |run --rm) postgres restore
```

{% hint style="warning" %}
It's a good practice to run your `backup` script regularly. For example, adding it to a cron job that runs periodically (i.e. every month, or every week)
{% endhint %}

## Backup to Amazon S3

After this [commit](https://github.com/papaemmelab/cookiecutter-api/commit/c379dab5344491bceaebaa74257352edaec83f70) in `cookiecutter-api`, you can store backups in the cloud in Amazon S3.  \
\
You need to add these 3 environment variables in your `.envs/.production/.django` file:

```bash
export DJANGO_AWS_ACCESS_KEY_ID=
export DJANGO_AWS_SECRET_ACCESS_KEY=
export DJANGO_AWS_STORAGE_BUCKET_NAME=
```

**4. Upload recursively all the database backups to your AWS S3 bucket**

```bash
docker-compose -f production.yml run --rm awscli upload
```

**5. Download a specific backup to your instance docker volume**

```bash
docker-compose -f production.yml run --rm awscli download backup_2018_03_13T09_05_07.sql.gz
```

Learn more at [cookicutter-django docs](#backup-to-amazon-s3).


---

# 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.isabl.io/maintenance.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.
