> ## Documentation Index
> Fetch the complete documentation index at: https://anaconda.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Backup and restore

This topic provides guidance on the following actions:

* [Backing up Anaconda Server](#backing-up-anaconda-server)
* [Restoring Anaconda Server](#restoring-anaconda-server)

## Backing up Anaconda Server

Follow these steps to back up your instance of Anaconda Server:

1. Install `pg_dump` and `pg_restore`.

2. Run the following command from the install directory:

   ```sh theme={null}
   # Replace <POSTGRES_PASSWORD> with your postgres password. You can find your postgres password here: <BASE_INSTALL_DIR>/config/postgres/postgres_db_password.txt
   ./repo-tools backup --database-uri postgresql://postgres:<POSTGRES_PASSWORD>@localhost:5432/postgres --keycloak-database-uri postgresql://keycloak:keycloak@localhost:5432/keycloak --blob-dir /opt/anaconda/repo/state/internal/blobs/ > repo.backup.zip
   ```

3. Save the `repo.backup.zip` file to a secure location.

4. Save the `REPO_TOKEN_CLIENT_SECRET` and `REPO_KEYCLOAK_SYNC_CLIENT_SECRET` values from the `.env` file in the installer directory.

## Restoring Anaconda Server

Follow these steps to restore your instance of Anaconda Server:

1. [Reinstall Anaconda Server](./instructions).

2. Reinstall `pg_dump` and `pg_restore` as shown [above](#backing-up-anaconda-server).

3. Copy the `repo.backup.zip` file.

4. Run the following command from the install directory:

   ```sh theme={null}
   # Replace <POSTGRES_PASSWORD> with your postgres password. You can find your postgres password here: <BASE_INSTALL_DIR>/config/postgres/postgres_db_password.txt
   ./repo-tools restore repo.backup.zip --database-uri postgresql://postgres:<POSTGRES_PASSWORD>@localhost:5432/postgres --keycloak-database-uri postgresql://keycloak:keycloak@localhost:5432/keycloak --blob-dir /opt/anaconda/repo/state/internal/blobs/
   ```

5. Modify the `.env` file in the install directory and replace `REPO_TOKEN_CLIENT_SECRET` and `REPO_KEYCLOAK_SYNC_CLIENT_SECRET` with the values saved earlier.

6. Run the following in the install directory:

   ```sh theme={null}
   docker-compose up -d repo_api
   ```
