> For the complete documentation index, see [llms.txt](https://docs.whitespots.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.whitespots.io/appsec-portal/deployment/database-transfer-guide.md).

# Database transfer guide

This guide outlines the steps to transfer a database using Docker and various commands. The process involves creating a database dump, transferring it to a remote server, and restoring it in a new container. If you have changed the default values for DB\_USERNAME and DB\_NAME, make sure to use your custom values in the commands provided below. Otherwise, the values of ***postgres*** should be used for both.

### Step 1: Preparing the New Host

Before transferring the database to the new host, ensure that the AppSec Portal is [installed](/appsec-portal/deployment/installation.md) and properly set up on new host. Follow the steps below to prepare the new host for the database migration:

1. Ensure that the AppSec Portal configuration is correctly set up on the new host, including database connection parameters. If the DB\_USERNAME and DB\_NAME was changed during the setup, make sure to use the custom values in the configuration.
2. Drop the Existing Database Inside the container, execute the following command to drop the existing database:

```
docker exec -i appsec-portal_postgres_1 dropdb -U <DB_USERNAME> <DB_NAME>
```

3. Create a New Database. While still inside the container, create a new database with the same name using the following command:

```
docker exec -i appsec-portal_postgres_1 createdb -U <DB_USERNAME> <DB_NAME>
```

### Step 2: Create a Database Dump on the Current Host

1. Open a terminal or command prompt. Navigate to the directory where you want to create the database dump file.

```
cd /path/to/destination_directory
```

2. Execute the following command to create a database dump from the current host:

```
docker exec -i appsec-portal_postgres_1 pg_dump -U <DB_USERNAME> <DB_NAME> > pg_dump
```

The pg\_dump file will be created in the previously specified directory.

### Step 3: Transfer the Database Dump to the New Host

Copy the database dump file (pg\_dump) to the new host using a secure method, such as SCP (Secure Copy) or any other file transfer mechanism you prefer.

### Step 4: Restore the Database on the New Host

1. Once the database dump file is on the new host, open a terminal or command prompt on the new host. Navigate to the directory where the database dump file is located.

```
cd /path/to/source_directory
```

2. Copy the database dump file into the appsec-portal\_postgres\_1 container on the new host:

```
docker cp pg_dump appsec-portal_postgres_1:/pg_dump
```

3. Restore the database from the dump on the new host inside the container:

```
docker exec -it appsec-portal_postgres_1 psql -U <DB_USERNAME> -d <DB_NAME> -f /pg_dump
```

Congratulations! You have successfully transferred the database.

{% hint style="info" %}
You can also use this guide to restore the database from a backup by skipping steps 2 and 3.
{% 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, and the optional `goal` query parameter:

```
GET https://docs.whitespots.io/appsec-portal/deployment/database-transfer-guide.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
