Database transfer guide

By following the steps outlined in this guide, you can safely and effectively transfer the AppSec Portal's database to a new host

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 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>
  1. 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
  1. 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
  1. 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
  1. 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.

You can also use this guide to restore the database from a backup by skipping steps 2 and 3.

Last updated