Skip to content

Commit

Permalink
Merge pull request #24 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 4.0.0 - Replace `b2` with `s3cmd` for copy to Backblaze B2 bucket
  • Loading branch information
dalenewby authored Jun 3, 2024
2 parents 84acbde + c48de74 commit 07dde8f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
9 changes: 1 addition & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
FROM python:3-alpine

# Variables set with ARG can be overridden at image build time with
# "--build-arg var=value". They are not available in the running container.
ARG B2_VERSION=v3.19.1

# Current version of s3cmd is in edge/testing repo
RUN echo https://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories

Expand All @@ -15,10 +11,7 @@ RUN apk update \
py3-magic \
py3-dateutil \
py3-six \
s3cmd \
&& wget -O /usr/local/bin/b2 \
https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/${B2_VERSION}/b2-linux \
&& chmod +x /usr/local/bin/b2
s3cmd

COPY application/ /data/
WORKDIR /data
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Service to backup and/or restore mysql databases to/from S3 and optionally to B2

`B2_APPLICATION_KEY` (optional; required if `B2_BUCKET` is defined) Backblaze application key secret

`B2_HOST` (optional; required if `B2_BUCKET` is defined) Backblaze B2 bucket's `Endpoint`

## Docker Hub
This image is built automatically on Docker Hub as [silintl/mysql-backup-restore](https://hub.docker.com/r/silintl/mysql-backup-restore/).

Expand Down
11 changes: 8 additions & 3 deletions application/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,19 @@ for dbName in ${DB_NAMES}; do

if [ "${B2_BUCKET}" != "" ]; then
start=$(date +%s)
b2 upload-file --no-progress --quiet ${B2_BUCKET} /tmp/${dbName}.sql.gz ${dbName}.sql.gz
s3cmd \
--access_key=${B2_APPLICATION_KEY_ID} \
--secret_key=${B2_APPLICATION_KEY} \
--host=${B2_HOST} \
--host-bucket='%(bucket)s.'"${B2_HOST}" \
put /tmp/${dbName}.sql.gz s3://${B2_BUCKET}/${dbName}.sql.gz
STATUS=$?
end=$(date +%s)
if [ $STATUS -ne 0 ]; then
echo "mysql-backup-restore: FATAL: Copy backup to ${B2_BUCKET} of ${dbName} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
echo "mysql-backup-restore: FATAL: Copy backup to Backblaze B2 bucket ${B2_BUCKET} of ${dbName} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
exit $STATUS
else
echo "mysql-backup-restore: Copy backup to ${B2_BUCKET} of ${dbName} completed in $(expr ${end} - ${start}) seconds."
echo "mysql-backup-restore: Copy backup to Backblaze B2 bucket ${B2_BUCKET} of ${dbName} completed in $(expr ${end} - ${start}) seconds."
fi
fi

Expand Down
1 change: 1 addition & 0 deletions local.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ S3_BUCKET=
B2_APPLICATION_KEY_ID=
B2_APPLICATION_KEY=
B2_BUCKET=
B2_HOST=

0 comments on commit 07dde8f

Please sign in to comment.