> For the complete documentation index, see [llms.txt](https://mp-access.gitbook.io/access/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mp-access.gitbook.io/access/operations/backups.md).

# Backups

## MongoDB

#### Create Backup

```bash
# ./scripts/backup-mongo.sh <backup filename prefix> <destinationfolder>

./scripts/backup-mongo.sh mongo backups/
```

#### Restore from Backup

```bash
# ./scripts/restore-mongo-backups.sh <Relative path to backup file>. 
# Expected structure inside backup folder mongo-xxx/access/
# info1-mngr@inforecover-exercises:~/backup/mongodump/access$ ls -l
# total 252256
# -rw-r--r-- 1 ... ... 258302988 Oct 23 18:28 studentSubmissions.bson
# -rw-r--r-- 1 ... ...       173 Oct 23 18:28 studentSubmissions.metadata.json

./scripts/backup-mongo.sh <backup filename prefix> <folder where to place backups
```

## Postgres

#### Create Backup

```bash
# ./scripts/backup-postgres.sh <backup filename prefix> <folder where to place backups>

./scripts/backup-postgres.sh dump backups/
```

#### Restore from Backup

```bash
# stop postgres and keycloak
docker-compose stop keycloak && docker-compose stop postgres

# remove any database files
rm -rf volumes/postgres/data/db/*

# restart postgres
docker-compose start postgres

# restore from backup
# ./scripts/restore-postgres-backups.sh <Relative path to backup file>
./scripts/restore-postgres-backups.sh backups/dump-2019-09-26_21_22_20.sql

# restart keycloak
docker-compose start keycloak
```

{% hint style="info" %}
If no root access, do the following for the 'remove any database files' step:

```
docker-compose exec postgres bash
rm -rf /var/lib/postgresql/data/*

# Exit container ctrl+d
docker-compose restart postgres
```

{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://mp-access.gitbook.io/access/operations/backups.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.
