-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #531 from PAWECOGmbH/development
Added the backup strategy
- Loading branch information
Showing
7 changed files
with
145 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# Activates the automatic export of variables | ||
set -a | ||
|
||
# Load the .env file | ||
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" | ||
source "$PROJECT_ROOT/.env" | ||
|
||
# Deactivates the automatic export of variables | ||
set +a | ||
|
||
# Checks whether the /backup folder exists and creates it if required | ||
if [ ! -d "/backup" ]; then | ||
mkdir -p /backup | ||
fi | ||
|
||
# Backup database | ||
docker compose -f compose-backup.yml run db_backup | ||
scp -i ${SSH_KEY_PATH} /backup/database.tar.gz ${SERVER_USER}@${SERVER_IP}:${REMOTE_BACKUP_PATH} | ||
|
||
# Backup userdata | ||
docker compose -f compose-backup.yml run userdata_backup | ||
scp -i ${SSH_KEY_PATH} /backup/userdata.tar.gz ${SERVER_USER}@${SERVER_IP}:${REMOTE_BACKUP_PATH} | ||
|
||
# Backup Lucee image | ||
docker compose -f compose-backup.yml run lucee_image_backup | ||
scp -i ${SSH_KEY_PATH} /backup/image_${LUCEE_IMAGE}_${LUCEE_IMAGE_VERSION}.tar ${SERVER_USER}@${SERVER_IP}:${REMOTE_BACKUP_PATH} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
services: | ||
db_backup: | ||
image: alpine | ||
volumes: | ||
- ${COMPOSE_PROJECT_NAME}_db_volume:/volume | ||
- /backup:/backup | ||
command: tar -czf /backup/database.tar.gz -C /volume . | ||
|
||
userdata_backup: | ||
image: alpine | ||
volumes: | ||
- ${COMPOSE_PROJECT_NAME}_userdata_volume:/volume | ||
- /backup:/backup | ||
command: tar -czf /backup/userdata.tar.gz -C /volume . | ||
|
||
lucee_image_backup: | ||
image: alpine | ||
volumes: | ||
- /backup:/backup | ||
command: docker save -o /backup/image_${LUCEE_IMAGE}_${LUCEE_IMAGE_VERSION}.tar ${LUCEE_IMAGE}:${LUCEE_IMAGE_VERSION} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
***Backup for the Production Environment*** | ||
|
||
**Purpose** | ||
|
||
This directory contains the configurations and scripts for backing up and restoring the database, user data, and the Lucee image. These backups are intended only for the production environment. | ||
|
||
By utilizing Docker Compose and shell scripts, the backup process is automated to ensure consistent and reliable data backups with minimal manual intervention. | ||
|
||
**Structure** | ||
|
||
- .env: This file contains environment variables specifically for backup and restoration in the production environment. Variables like volume names, image versions, and SSH credentials are defined here. | ||
|
||
- compose-backup.yml: This file defines the container services needed to create backups. Each service performs a backup for the database, user data, or the Lucee image. | ||
|
||
- backup.sh: A shell script that automates the process of backing up the database, user data, and Lucee image. It uses Docker Compose and secure copying (SCP) to transfer backups to the designated backup server. | ||
|
||
- restore.sh: A shell script that automates the process of restoring the database, user data, and Lucee image. It retrieves backups from the backup server and restores them to the appropriate volumes. | ||
|
||
**Usage** | ||
|
||
*Backup* | ||
|
||
To create a backup, run the following command from this directory: | ||
|
||
sh backup.sh | ||
|
||
This will: | ||
1. Backup the database volume. | ||
2. Backup the user data volume. | ||
3. Backup the Lucee image. | ||
4. Securely transfer all backups to the remote backup server. | ||
|
||
*Restore* | ||
To restore from a backup, run the following command: | ||
|
||
sh restore.sh | ||
|
||
This will: | ||
|
||
1. Retrieve the latest backups from the remote backup server. | ||
2. Restore the database volume. | ||
3. Restore the user data volume. | ||
4. Load the Lucee image into Docker. | ||
|
||
**Notes** | ||
- The backups created by this process are only for the **production environment**. Please ensure that the environment variables in the `.env` file are configured correctly before running any backups or restores. | ||
|
||
- Make sure to update the `.env` file with the correct values (such as volume names, SSH keys, and server IP) specific to the production setup. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
# Activates the automatic export of variables | ||
set -a | ||
|
||
# Load the .env file | ||
source /.env | ||
|
||
# Deactivates the automatic export of variables | ||
set +a | ||
|
||
# Checks whether the /restore folder exists and creates it if required | ||
if [ ! -d "/restore" ]; then | ||
mkdir -p /restore | ||
fi | ||
|
||
# Restore database | ||
scp -i ${SSH_KEY_PATH} ${SERVER_USER}@${SERVER_IP}:${REMOTE_BACKUP_PATH}/database.tar.gz /restore/ | ||
docker run --rm -v ${COMPOSE_PROJECT_NAME}_db_volume:/volume -v /restore:/backup alpine sh -c "cd /volume && tar -xzf /backup/database.tar.gz" | ||
docker restart ${MYSQL_CONTAINER_NAME} | ||
|
||
# Restore userdata | ||
scp -i ${SSH_KEY_PATH} ${SERVER_USER}@${SERVER_IP}:${REMOTE_BACKUP_PATH}/userdata.tar.gz /restore/ | ||
docker run --rm -v ${COMPOSE_PROJECT_NAME}_userdata_volume:/volume -v /restore:/backup alpine sh -c "cd /volume && tar -xzf /backup/userdata.tar.gz" | ||
docker restart ${LUCEE_CONTAINER_NAME} | ||
|
||
# Restore Lucee image | ||
scp -i ${SSH_KEY_PATH} ${SERVER_USER}@${SERVER_IP}:${REMOTE_BACKUP_PATH}/image_${LUCEE_IMAGE}_${LUCEE_IMAGE_VERSION}.tar /restore/ | ||
docker load -i /restore/image_${LUCEE_IMAGE}_${LUCEE_IMAGE_VERSION}.tar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters