Skip to content

Commit 0ecc492

Browse files
authored
Merge pull request #20 from silinternational/develop
Release 3.1.0
2 parents 99e7336 + ac8aefa commit 0ecc492

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
lines changed

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
FROM python:3-alpine
22

3+
# Variables set with ARG can be overridden at image build time with
4+
# "--build-arg var=value". They are not available in the running container.
5+
ARG B2_VERSION=v3.19.1
6+
37
# Current version of s3cmd is in edge/testing repo
48
RUN echo https://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
59

@@ -11,7 +15,10 @@ RUN apk update \
1115
py3-magic \
1216
py3-dateutil \
1317
py3-six \
14-
s3cmd
18+
s3cmd \
19+
&& wget -O /usr/local/bin/b2 \
20+
https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/${B2_VERSION}/b2-linux \
21+
&& chmod +x /usr/local/bin/b2
1522

1623
COPY application/ /data/
1724
WORKDIR /data

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
start: restore backup
22

33
restore: db
4-
docker-compose up -d restore
4+
docker compose up -d restore
55

66
backup: db
7-
docker-compose up -d backup
7+
docker compose up -d backup
88

99
db:
10-
docker-compose up -d db phpmyadmin
10+
docker compose up -d db phpmyadmin
1111

1212
clean:
13-
docker-compose kill
13+
docker compose kill
1414
docker system prune -f

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# mysql-backup-restore
2-
Service to backup and/or restore mysql databases to/from S3
2+
Service to backup and/or restore mysql databases to/from S3 and optionally to B2
33

44
## How to use it
55
1. Create an S3 bucket to hold your backups
66
2. Turn versioning on for that bucket
7+
2. (Optional) Create a B2 bucket to hold your backups
78
3. Supply all appropriate environment variables
8-
4. Run a backup and check your bucket for that backup
9+
4. Run a backup and check your bucket(s) for that backup
910

1011
### Environment variables
11-
`MODE` Valid values: `backup`, `restore`
12+
`MODE` Valid values: `backup`, `restore`. Restores are implemented **only** from S3.
1213

1314
`DB_NAMES` list of the database names
1415

@@ -18,19 +19,27 @@ Service to backup and/or restore mysql databases to/from S3
1819

1920
`MYSQL_DUMP_ARGS` (optional) additional arguments to the mysqldump command, e.g., `--max_allowed_packet=50M`
2021

22+
`S3_BUCKET` e.g., _s3://database-backups_ **NOTE: no trailing slash**
23+
24+
>**It's recommended that your S3 bucket have versioning turned on.** Each backup creates a file of the form _dbname_.sql.gz. If versioning is not turned on, the previous backup file will be replaced with the new one, resulting in a single level of backups.
25+
2126
`AWS_ACCESS_KEY` used for S3 interactions
2227

2328
`AWS_SECRET_KEY` used for S3 interactions
2429

25-
`S3_BUCKET` e.g., _s3://database-backups_ **NOTE: no trailing slash**
30+
`B2_BUCKET` (optional) Name of the Backblaze B2 bucket, e.g., _database-backups_. When `B2_BUCKET` is defined, the backup file is copied to the B2 bucket in addition to the S3 bucket.
31+
32+
>**It's recommended that your B2 bucket have versioning and encryption turned on.** Each backup creates a file of the form _dbname_.sql.gz. If versioning is not turned on, the previous backup file will be replaced with the new one, resulting in a single level of backups. Encryption may offer an additional level of protection from attackers. It also has the side effect of preventing downloads of the file via the Backblaze GUI (you'll have to use the `b2` command or the Backblaze API).
33+
34+
`B2_APPLICATION_KEY_ID` (optional; required if `B2_BUCKET` is defined) Backblaze application key ID
2635

27-
>**It's recommended that your S3 bucket have versioning turned on.**
36+
`B2_APPLICATION_KEY` (optional; required if `B2_BUCKET` is defined) Backblaze application key secret
2837

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

3241
## Playing with it locally
33-
You'll need [Docker](https://www.docker.com/get-docker), [Docker Compose](https://docs.docker.com/compose/install/), and [Make](https://www.gnu.org/software/make/).
42+
You'll need [Docker Engine](https://docs.docker.com/engine/) with the Docker Compose plugin and [Make](https://www.gnu.org/software/make/).
3443

3544
1. cd .../mysql-backup-restore
3645
3. Upload test/world.sql.gz to the S3 bucket.

application/backup.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ for dbName in ${DB_NAMES}; do
6060
else
6161
echo "mysql-backup-restore: Copy backup to ${S3_BUCKET} of ${dbName} completed in $(expr ${end} - ${start}) seconds."
6262
fi
63+
64+
if [ "${B2_BUCKET}" != "" ]; then
65+
start=$(date +%s)
66+
b2 upload-file --noProgress --quiet ${B2_BUCKET} /tmp/${dbName}.sql.gz ${dbName}.sql.gz
67+
STATUS=$?
68+
end=$(date +%s)
69+
if [ $STATUS -ne 0 ]; then
70+
echo "mysql-backup-restore: FATAL: Copy backup to ${B2_BUCKET} of ${dbName} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
71+
exit $STATUS
72+
else
73+
echo "mysql-backup-restore: Copy backup to ${B2_BUCKET} of ${dbName} completed in $(expr ${end} - ${start}) seconds."
74+
fi
75+
fi
76+
6377
done
6478

6579
echo "mysql-backup-restore: backup: Completed"

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '2'
21
services:
32
data:
43
image: silintl/data-volume:latest

local.env.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
AWS_ACCESS_KEY=
22
AWS_SECRET_KEY=
33
S3_BUCKET=
4+
B2_APPLICATION_KEY_ID=
5+
B2_APPLICATION_KEY=
6+
B2_BUCKET=

0 commit comments

Comments
 (0)