Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webroot + db backup script #53

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/build-db-webroot-backup.yml
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 9 additions & 0 deletions db-webroot-backup/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
34 changes: 34 additions & 0 deletions db-webroot-backup/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/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)

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"

# 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}/"