From 4b2b3acc0d5f0fde780970ee0bf28c835b844961 Mon Sep 17 00:00:00 2001 From: jankovicn Date: Thu, 22 Jul 2021 15:11:06 +0200 Subject: [PATCH 1/3] added section on database backup --- documentation/operator-guide/management.rst | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/documentation/operator-guide/management.rst b/documentation/operator-guide/management.rst index 4773ecad..f25d2181 100644 --- a/documentation/operator-guide/management.rst +++ b/documentation/operator-guide/management.rst @@ -167,3 +167,34 @@ Additionally in order to delete older logs from docker containers present on a n The final section :ref:`ingestion` explains how to get data into the VS. + +Database backup +---------------- + +The database can be backed up with the script below. The `STACK` and `BACKUP_PATH` variables can be changed depending on the stack and desired path where the backed up files will be stored + +.. code-block:: shell + + #!/bin/bash + + # Variables to be changed + STACK="dem" + BACKUP_PATH="/path/to/backup/storage" + + # Script variables + FILE_NAME="$(date +'%Y%m%d').tar.gz" + DB_SERVICE=""$STACK"_database" + DB_CONTAINER="$(docker ps -q -f name=$DB_SERVICE)" + + echo "Backing up $STACK stack" + echo "Backup path: $BACKUP_PATH" + echo "Backup file: $FILE_NAME" + echo "Backup service: $DB_SERVICE" + echo "DB container id: $DB_CONTAINER" + + echo "Backing up to /$FILE_NAME" + docker exec $DB_CONTAINER sh -c "pg_dump -U "$STACK"_user -d "$STACK"_db -f c > /$FILE_NAME" + echo "Copying to $BACKUP_PATH" + docker cp $DB_CONTAINER:/$FILE_NAME $BACKUP_PATH + echo "Cleaning up" + docker exec $DB_CONTAINER sh -c "rm /$FILE_NAME" -- GitLab From 13f2731cc2ed7337f476c63e0df133bf47bfdeda Mon Sep 17 00:00:00 2001 From: jankovicn Date: Thu, 22 Jul 2021 15:45:27 +0200 Subject: [PATCH 2/3] updated wording --- documentation/operator-guide/management.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/operator-guide/management.rst b/documentation/operator-guide/management.rst index f25d2181..94165022 100644 --- a/documentation/operator-guide/management.rst +++ b/documentation/operator-guide/management.rst @@ -171,7 +171,7 @@ The final section :ref:`ingestion` explains how to get data into the VS. Database backup ---------------- -The database can be backed up with the script below. The `STACK` and `BACKUP_PATH` variables can be changed depending on the stack and desired path where the backed up files will be stored +The database can be backed up with the script below. The `STACK` and `BACKUP_PATH` variables can be changed depending on the stack and desired path of backup files .. code-block:: shell -- GitLab From fc64c83fc24add8f8b80deb89810a414d374ce2f Mon Sep 17 00:00:00 2001 From: jankovicn Date: Thu, 22 Jul 2021 18:24:06 +0200 Subject: [PATCH 3/3] added restore script --- documentation/operator-guide/management.rst | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/documentation/operator-guide/management.rst b/documentation/operator-guide/management.rst index 94165022..6f62fc55 100644 --- a/documentation/operator-guide/management.rst +++ b/documentation/operator-guide/management.rst @@ -198,3 +198,35 @@ The database can be backed up with the script below. The `STACK` and `BACKUP_PAT docker cp $DB_CONTAINER:/$FILE_NAME $BACKUP_PATH echo "Cleaning up" docker exec $DB_CONTAINER sh -c "rm /$FILE_NAME" + +To restore from a backed up file run the below script. Here the `STACK`, `DATE` and `BACKUP_PATH` can be changed. Note: Date for last backup must be in YYYYMMDD format + +.. code-block:: shell + + #!/bin/bash + + # Variables to be changed + STACK="dem" + DATE="20210722" + BACKUP_PATH="/path/to/backups" + + # Script variables + BACKUP_FILE="$BACKUP_PATH/$DATE.sql.gz" + UNCOMPRESSED_FILE="$BACKUP_PATH/$DATE.sql" + DB_SERVICE=""$STACK"_database" + DB_CONTAINER="$(docker ps -q -f name=$DB_SERVICE)" + + echo "Restoring $STACK stack" + echo "Backup file: $BACKUP_FILE" + echo "Backup service: $DB_SERVICE" + echo "DB container id: $DB_CONTAINER" + + echo "Unpacking $BACKUP_FILE" + gunzip $BACKUP_FILE + echo "Copying unpacked file" + docker cp $UNCOMPRESSED_FILE $DB_CONTAINER:/ + echo "Restoring database" + docker exec $DB_CONTAINER sh -c "psql -U "$STACK"_user -d "$STACK"_db < /$DATE.sql" + echo "Cleaning up" + docker exec $DB_CONTAINER sh -c "rm /$DATE.sql" + rm $UNCOMPRESSED_FILE -- GitLab