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

Mysql backup - add support for Docker secrets via _FILE env vars #134

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 33 additions & 3 deletions mysql-backup-s3/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
FROM alpine:latest
FROM alpine:3.13
LABEL maintainer="Johannes Schickling <[email protected]>"

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
Expand Down
7 changes: 6 additions & 1 deletion mysql-backup-s3/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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.
Expand Down
18 changes: 17 additions & 1 deletion mysql-backup-s3/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
25 changes: 0 additions & 25 deletions mysql-backup-s3/install.sh

This file was deleted.