Skip to main content

Exercise 2

Scenario

Application, database, and datacenter failures must be accounted for in your Disaster Recovery Plan. To successfully execute this plan, application administrators must know how to backup and recover the database and flat files.

User-uploaded files and pipeline scripts/log files that are referenced by the database are written as physical files to disk and are not stored inside the database as blobs for a number of reasons, such as performance.

2986737749.jpg

Your Task

Part 1: Database and flat file backup

Backup the L7|ESP database, followed by the shared data volume /opt/l7esp/data

To generate data for this exercise, run the following commands sequentially:

1 docker-compose exec server bash
2 source ~/data/extensions/client/bin/activate
3 pip install pytest
4 pytest --password 'Password12!' tests/test_content.py::TestBloodBankingTraining

1) Create a backup directory from within project folder:

mkdir -pv ./backup && cd ./backup

2) Backup the database (local DB with the container image) using the command below. *Use today’s date in ISO format

pg_dump --host localhost \
--port 1487 \
--dbname lab7 \
--clean \
--if-exists \
--format=c > \
./esp_db_20230302.pgdump 

3) Backup the shared data volume using the command:

rsync --verbose \
--archive \
--exclude 'log/' \
--exclude 'run/' \
--exclude 'database/' \
--exclude 'project/' ~/data/  \
./

Hint: PostgreSQL database backups

Part 2: Drop and recreate the database

Drop and recreate the database by running the commands below:

1 docker-compose down --volumes 
2 docker-compose up --detach

Part 3: Database and flat file recovery

Restore the L7|ESP database and its associated flat files.

1) Shell back into the container using docker compose exec server bash

2) Stop all L7|ESP services except for the database with the command:

1 l7 stop $(l7 status | grep -v database | grep RUNNING | awk '{print $1}')

3) Change directory into the backup folder:

cd ./backup

4) Restore the database with the command:

pg_restore --host localhost \
--port 1487 \
--dbname lab7 \
--clean \
--if-exists \
--no-owner \
./<backup_file>

5) Restore the shared data volume with the command:

rsync \
--verbose \
--archive \
--exclude 'log/' \
--exclude 'run/' \
--exclude 'database/' \
--exclude 'project/' \
--exclude 'backup/' ~/data/  \
./ 

6) Start all L7|ESP Services:

1 l7 start