-
Notifications
You must be signed in to change notification settings - Fork 2
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 #53 from Chia-Network/website-backup
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 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
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" |
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,9 @@ | ||
FROM alpine:latest | ||
|
||
RUN apk add mysql-client aws-cli | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
RUN chmod +x /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
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,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}/" |