Database backup

In general, Diffblue recommends that you backup your Cover Reports database, in line with your standard backup procedures. Follow the instructions below for the default H2 database or optional (production grade environment) PostgreSQL database.

H2 database

When using the ZIP or EXE installation, the H2 database is used by default.

To backup and/or restore the H2 database, refer to the H2 Docs Backup & Restore docs topic.

Alternatively, you can simply copy the H2 database files on the host filesystem (command example below):

  1. On the Cover Reports server, stop the Cover Reports application (if currently running).

  2. Navigate to the directory where the database files are kept. By default, these are located in the same folder where Cover Reports was started, although this is configurable.

  3. Copy all the database files to a different directory that will prevent them from being removed or changed.

$ cd directory-where-database-files-are-kept
$ cp *.db secure-backup-directory/

Note: This mechanism of backup is not recommended because it will lead to discrepancies if the H2 version changes.

To restore the database:

  • Stop the Cover Reports application.

  • Copy the database files from the backup directory into the directory where Reports is to be started.

  • Start Reports as normal from that directory.

PostgreSQL database

When using an external PostgreSQL database, the standard PostgreSQL backup utilities can be used - see the PostgreSQL Backup & Restore docs topic. However, since PostgreSQL is run inside a Docker container using Docker Compose, the commands must be run through Docker Compose. Therefore, to back up the database (command example below):

  1. Navigate to the directory where the docker-compose.yml is located.

  2. Generate a backup file from the running database.

  3. Copy the file into a different directory that will prevent it from being removed or changed.

$ cd $COVER_REPORTS_INSTALL_DIR
$ docker compose exec -T -u postgres postgres pg_dumpall > ./pg_dump.sql.backup
$ cp ./pg_dump.sql.backup secure-backup-directory/

To restore the database from a backup file (command example below):

  1. Navigate to the directory where the docker-compose.yml is located.

  2. Stop all the Docker containers. This closes any active database sessions.

  3. Start only the Postgres Docker container.

  4. Copy the backup file to the Postgres Docker container.

  5. Restore the database using the backup.

  6. Restart all the containers in the normal order.

$ cd $COVER_REPORTS_INSTALL_DIR
$ docker compose down
$ docker compose up -d postgres
$ docker compose cp ./pg_dump.sql.backup postgres:/pg_dump.sql.backup
$ docker compose exec -T -u postgres postgres psql -c 'DROP DATABASE IF EXISTS reports' -f ./pg_dump.sql.backup postgres
$ docker compose up -d

Last updated