Olivier Pichon
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
56 additions and
30 deletions
-
mysql-backup-s3/Dockerfile
-
mysql-backup-s3/README.md
-
mysql-backup-s3/backup.sh
-
mysql-backup-s3/install.sh
|
|
@ -1,8 +1,38 @@ |
|
|
|
FROM alpine:latest |
|
|
|
FROM alpine:3.13 |
|
|
|
LABEL maintainer="Johannes Schickling <schickling.j@gmail.com>" |
|
|
|
|
|
|
|
ADD install.sh install.sh |
|
|
|
RUN sh install.sh && rm install.sh |
|
|
|
ENV GLIBC_VER=2.33-r0 |
|
|
|
|
|
|
|
# install glibc compatibility for alpine |
|
|
|
RUN apk --no-cache add \ |
|
|
|
binutils \ |
|
|
|
curl \ |
|
|
|
&& curl -sL https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub \ |
|
|
|
&& curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-${GLIBC_VER}.apk \ |
|
|
|
&& curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk \ |
|
|
|
&& curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-i18n-${GLIBC_VER}.apk \ |
|
|
|
&& apk add --no-cache \ |
|
|
|
glibc-${GLIBC_VER}.apk \ |
|
|
|
glibc-bin-${GLIBC_VER}.apk \ |
|
|
|
glibc-i18n-${GLIBC_VER}.apk \ |
|
|
|
mysql-client \ |
|
|
|
&& /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8 \ |
|
|
|
&& curl -sL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip \ |
|
|
|
&& unzip awscliv2.zip \ |
|
|
|
&& aws/install \ |
|
|
|
&& rm -rf \ |
|
|
|
awscliv2.zip \ |
|
|
|
aws \ |
|
|
|
/usr/local/aws-cli/v2/*/dist/aws_completer \ |
|
|
|
/usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \ |
|
|
|
/usr/local/aws-cli/v2/*/dist/awscli/examples \ |
|
|
|
glibc-*.apk \ |
|
|
|
&& curl -L --insecure https://github.com/odise/go-cron/releases/download/v0.0.6/go-cron-linux.gz | zcat > /usr/local/bin/go-cron \ |
|
|
|
&& chmod u+x /usr/local/bin/go-cron \ |
|
|
|
&& apk --no-cache del \ |
|
|
|
binutils \ |
|
|
|
curl \ |
|
|
|
&& rm -rf /var/cache/apk/* |
|
|
|
|
|
|
|
ENV MYSQLDUMP_OPTIONS --quote-names --quick --add-drop-table --add-locks --allow-keywords --disable-keys --extended-insert --single-transaction --create-options --comments --net_buffer_length=16384 |
|
|
|
ENV MYSQLDUMP_DATABASE --all-databases |
|
|
|
|
|
@ -1,6 +1,8 @@ |
|
|
|
# mysql-backup-s3 |
|
|
|
|
|
|
|
Backup MySQL to S3 (supports periodic backups & mutli files) |
|
|
|
Backup MySQL to S3 (supports periodic backups & mutli files) using AWS CLI v2. |
|
|
|
|
|
|
|
Forked from https://github.com/schickling/dockerfiles. |
|
|
|
|
|
|
|
## Basic usage |
|
|
|
|
|
|
@ -16,8 +18,11 @@ $ docker run -e S3_ACCESS_KEY_ID=key -e S3_SECRET_ACCESS_KEY=secret -e S3_BUCKET |
|
|
|
- `MYSQL_PORT` the mysql port (default: 3306) |
|
|
|
- `MYSQL_USER` the mysql user *required* |
|
|
|
- `MYSQL_PASSWORD` the mysql password *required* |
|
|
|
- `MYSQL_PASSWORD_FILE` path to file containing the mysql password; alternative to `MYSQL_PASSWORD` |
|
|
|
- `S3_ACCESS_KEY_ID` your AWS access key *required* |
|
|
|
- `S3_ACCESS_KEY_ID_FILE` path to file containing your AWS access key; alternative to `S3_ACCESS_KEY_ID` |
|
|
|
- `S3_SECRET_ACCESS_KEY` your AWS secret key *required* |
|
|
|
- `S3_SECRET_ACCESS_KEY_FILE` path to file containing your AWS secret key; alternative to `S3_SECRET_ACCESS_KEYs` |
|
|
|
- `S3_BUCKET` your AWS S3 bucket path *required* |
|
|
|
- `S3_PREFIX` path prefix in your bucket (default: 'backup') |
|
|
|
- `S3_FILENAME` a consistent filename to overwrite with your backup. If not set will use a timestamp. |
|
|
|
|
|
@ -2,6 +2,21 @@ |
|
|
|
|
|
|
|
set -e |
|
|
|
|
|
|
|
if [ -n "${MYSQL_PASSWORD_FILE}" ]; then |
|
|
|
MYSQL_PASSWORD=$(cat "$MYSQL_PASSWORD_FILE") |
|
|
|
export MYSQL_PASSWORD |
|
|
|
fi |
|
|
|
|
|
|
|
if [ -n "${S3_ACCESS_KEY_ID_FILE}" ]; then |
|
|
|
S3_ACCESS_KEY_ID=$(cat "$S3_ACCESS_KEY_ID_FILE") |
|
|
|
export S3_ACCESS_KEY_ID |
|
|
|
fi |
|
|
|
|
|
|
|
if [ -n "${S3_SECRET_ACCESS_KEY_FILE}" ]; then |
|
|
|
S3_SECRET_ACCESS_KEY=$(cat "$S3_SECRET_ACCESS_KEY_FILE") |
|
|
|
export S3_SECRET_ACCESS_KEY |
|
|
|
fi |
|
|
|
|
|
|
|
if [ "${S3_ACCESS_KEY_ID}" == "**None**" ]; then |
|
|
|
echo "Warning: You did not set the S3_ACCESS_KEY_ID environment variable." |
|
|
|
fi |
|
|
@ -50,7 +65,7 @@ copy_s3 () { |
|
|
|
AWS_ARGS="--endpoint-url ${S3_ENDPOINT}" |
|
|
|
fi |
|
|
|
|
|
|
|
echo "Uploading ${DEST_FILE} on S3..." |
|
|
|
echo "Uploading ${DEST_FILE} to S3..." |
|
|
|
|
|
|
|
cat $SRC_FILE | aws $AWS_ARGS s3 cp - s3://$S3_BUCKET/$S3_PREFIX/$DEST_FILE |
|
|
|
|
|
|
@ -60,6 +75,7 @@ copy_s3 () { |
|
|
|
|
|
|
|
rm $SRC_FILE |
|
|
|
} |
|
|
|
|
|
|
|
# Multi file: yes |
|
|
|
if [ ! -z "$(echo $MULTI_FILES | grep -i -E "(yes|true|1)")" ]; then |
|
|
|
if [ "${MYSQLDUMP_DATABASE}" == "--all-databases" ]; then |
|
|
|
|
|
@ -1,25 +0,0 @@ |
|
|
|
#! /bin/sh |
|
|
|
|
|
|
|
# exit if a command fails |
|
|
|
set -e |
|
|
|
|
|
|
|
|
|
|
|
apk update |
|
|
|
|
|
|
|
# install mysqldump |
|
|
|
apk add mysql-client |
|
|
|
|
|
|
|
# install s3 tools |
|
|
|
apk add python py-pip |
|
|
|
pip install awscli |
|
|
|
apk del py-pip |
|
|
|
|
|
|
|
# install go-cron |
|
|
|
apk add curl |
|
|
|
curl -L --insecure https://github.com/odise/go-cron/releases/download/v0.0.6/go-cron-linux.gz | zcat > /usr/local/bin/go-cron |
|
|
|
chmod u+x /usr/local/bin/go-cron |
|
|
|
apk del curl |
|
|
|
|
|
|
|
|
|
|
|
# cleanup |
|
|
|
rm -rf /var/cache/apk/* |