Browse Source

feat(mysql-backup-s3): install glibc and aws cli v2

pull/134/head
Olivier Pichon 4 years ago
parent
commit
bd59ea05be
  1. 36
      mysql-backup-s3/Dockerfile
  2. 5
      mysql-backup-s3/README.md
  3. 15
      mysql-backup-s3/backup.sh
  4. 25
      mysql-backup-s3/install.sh

36
mysql-backup-s3/Dockerfile

@ -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

5
mysql-backup-s3/README.md

@ -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
@ -18,6 +20,7 @@ $ docker run -e S3_ACCESS_KEY_ID=key -e S3_SECRET_ACCESS_KEY=secret -e S3_BUCKET
- `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*

15
mysql-backup-s3/backup.sh

@ -3,11 +3,18 @@
set -e
if [ -n "${MYSQL_PASSWORD_FILE}" ]; then
export MYSQL_PASSWORD=$(cat $MYSQL_PASSWORD_FILE)
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
export S3_SECRET_ACCESS_KEY=$(cat $S3_SECRET_ACCESS_KEY_FILE)
S3_SECRET_ACCESS_KEY=$(cat "$S3_SECRET_ACCESS_KEY_FILE")
export S3_SECRET_ACCESS_KEY
fi
if [ "${S3_ACCESS_KEY_ID}" == "**None**" ]; then
@ -58,7 +65,8 @@ copy_s3 () {
AWS_ARGS="--endpoint-url ${S3_ENDPOINT}"
fi
echo "Uploading ${DEST_FILE} on S3..."
echo "$AWS_ARGS"
echo "Uploading ${DEST_FILE} to S3..."
cat $SRC_FILE | aws $AWS_ARGS s3 cp - s3://$S3_BUCKET/$S3_PREFIX/$DEST_FILE
@ -68,6 +76,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

25
mysql-backup-s3/install.sh

@ -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/*
Loading…
Cancel
Save