From 2a43eb33607b247baba8ff3a3d351235c1c99c7d Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Mon, 20 Nov 2023 14:52:37 -0600 Subject: [PATCH 1/3] Add webroot + db backup script --- db-webroot-backup/Dockerfile | 9 +++++++++ db-webroot-backup/entrypoint.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 db-webroot-backup/Dockerfile create mode 100644 db-webroot-backup/entrypoint.sh diff --git a/db-webroot-backup/Dockerfile b/db-webroot-backup/Dockerfile new file mode 100644 index 0000000..e5c815e --- /dev/null +++ b/db-webroot-backup/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:latest + +RUN apk add mysql-client aws-cli + +COPY entrypoint.sh /entrypoint.sh + +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/db-webroot-backup/entrypoint.sh b/db-webroot-backup/entrypoint.sh new file mode 100644 index 0000000..78a658e --- /dev/null +++ b/db-webroot-backup/entrypoint.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +check_env_var() { + var_name=$1 + eval var_value="\$$var_name" + + if [ -z "$var_value" ]; then + echo "Error: Environment variable $var_name is not set or is empty." + exit 1 + fi +} + +# Check required environment variables +check_env_var "SITENAME" +check_env_var "WEBROOT_PATH" +check_env_var "DB_HOST" +check_env_var "DB_NAME" +check_env_var "DB_USER" +check_env_var "DB_PASS" +check_env_var "BUCKET_NAME" + +DATE=$(date +%d%m%y%H%M) + +# export database +mysqldump --single-transaction -h "$DB_HOST" -u "$DB_USER" "-p${DB_PASS}" "$DB_NAME" | gzip > "/tmp/site-backup/${SITENAME}_${DATE}.sql.gz" + +# export files +tar cvzf "/tmp/site-backup/${SITENAME}_${DATE}.tar.gz" -C "$WEBROOT_PATH" + +# sync to amazon +aws s3 cp "/tmp/site-backup/${SITENAME}_${DATE}.sql.gz" "s3://${BUCKET_NAME}/" +aws s3 cp "/tmp/site-backup/${SITENAME}_${DATE}.tar.gz" "s3://${BUCKET_NAME}/" From 2dd18bb331fc1abe28d56835b8c3ab4d2008aa5e Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Mon, 20 Nov 2023 14:55:27 -0600 Subject: [PATCH 2/3] Add a backup db/webroot backup image --- .github/workflows/build-db-webroot-backup.yml | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/build-db-webroot-backup.yml diff --git a/.github/workflows/build-db-webroot-backup.yml b/.github/workflows/build-db-webroot-backup.yml new file mode 100644 index 0000000..06f3432 --- /dev/null +++ b/.github/workflows/build-db-webroot-backup.yml @@ -0,0 +1,29 @@ +name: Build DB/Webroot Backup Image + +on: + push: + branches: + - main + paths: + - 'db-webroot-backup/*' + - '.github/workflows/build-db-webroot-backup.yml' + pull_request: + paths: + - 'db-webroot-backup/*' + - '.github/workflows/build-db-webroot-backup.yml' + workflow_dispatch: + schedule: + - cron: '30 12 * * 5' + +concurrency: + # SHA is added to the end if on `main` to let all main workflows run + group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ github.ref == 'refs/heads/main' && github.sha || '' }} + cancel-in-progress: true + +jobs: + package: + uses: Chia-Network/actions/.github/workflows/docker-build.yaml@main + with: + docker-context: "./db-webroot-backup" + dockerfile: "./db-webroot-backup/Dockerfile" + image_subpath: "db-webroot-backup" From 1bc9758bf6d59fb8784683ca43a34e3d37d07ae9 Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Mon, 20 Nov 2023 14:56:29 -0600 Subject: [PATCH 3/3] Make sure temp dir exists --- db-webroot-backup/entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db-webroot-backup/entrypoint.sh b/db-webroot-backup/entrypoint.sh index 78a658e..a60f385 100644 --- a/db-webroot-backup/entrypoint.sh +++ b/db-webroot-backup/entrypoint.sh @@ -21,6 +21,8 @@ check_env_var "BUCKET_NAME" DATE=$(date +%d%m%y%H%M) +mkdir -p /tmp/site-backup/ + # export database mysqldump --single-transaction -h "$DB_HOST" -u "$DB_USER" "-p${DB_PASS}" "$DB_NAME" | gzip > "/tmp/site-backup/${SITENAME}_${DATE}.sql.gz"