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

[WIP] Dump and import using a S3 bucket. #1

Open
wants to merge 1 commit 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
11 changes: 9 additions & 2 deletions Docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
FROM alpine:3.4
RUN apk add --update mysql-client bash openssh-client && rm -rf /var/cache/apk/*
FROM alpine:3.6
RUN mkdir -p /mysqldump && \
apk add --update mysql-client bash openssh-client groff less python py-pip && \
pip install awscli && \
apk --purge -v del py-pip && \
rm /var/cache/apk/*

WORKDIR /mysqldump

COPY dump.sh /
COPY import.sh /
ENTRYPOINT ["/dump.sh"]
19 changes: 17 additions & 2 deletions Docker/dump.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

set -e
set -o pipefail

AWS_BUCKET=${AWS_BUCKET:-${MYSQL_ENV_AWS_BUCKET}}
AWS_BUCKET_PREFIX=${AWS_BUCKET_PREFIX:-${MYSQL_ENV_AWS_BUCKET_PREFIX}}
DB_USER=${DB_USER:-${MYSQL_ENV_DB_USER}}
DB_PASS=${DB_PASS:-${MYSQL_ENV_DB_PASS}}
DB_NAME=${DB_NAME:-${MYSQL_ENV_DB_NAME}}
Expand All @@ -8,6 +13,16 @@ ALL_DATABASES=${ALL_DATABASES}
IGNORE_DATABASE=${IGNORE_DATABASE}


if [ "${AWS_BUCKET}" == "" ]; then
echo "Missing AWS_BUCKET env variable"
exit 1
fi

if [ "${AWS_BUCKET_PREFIX}" == "" ]; then
echo "Missing AWS_BUCKET_PREFIX env variable"
exit 1
fi

if [[ ${DB_USER} == "" ]]; then
echo "Missing DB_USER env variable"
exit 1
Expand All @@ -26,13 +41,13 @@ if [[ ${ALL_DATABASES} == "" ]]; then
echo "Missing DB_NAME env variable"
exit 1
fi
mysqldump --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" "$@" "${DB_NAME}" > /mysqldump/"${DB_NAME}".sql
mysqldump --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" "$@" "${DB_NAME}" | gzip | aws s3 cp - s3://$AWS_BUCKET/$AWS_BUCKET_PREFIX/$(date +"%Y")/$(date +"%m")/$(date +"%d")/"${DB_NAME}".sql.gz
else
databases=`mysql --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] && [[ "$db" != "$IGNORE_DATABASE" ]]; then
echo "Dumping database: $db"
mysqldump --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" --databases $db > /mysqldump/$db.sql
mysqldump --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" --databases $db | gzip | aws s3 cp - s3://$AWS_BUCKET/$AWS_BUCKET_PREFIX/$(date +"%Y")/$(date +"%m")/$(date +"%d")/$db.sql.gz
fi
done
fi
25 changes: 24 additions & 1 deletion Docker/import.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
#!/bin/bash

set -e
set -o pipefail

AWS_BUCKET=${AWS_BUCKET:-${MYSQL_ENV_AWS_BUCKET}}
AWS_BUCKET_PREFIX=${AWS_BUCKET_PREFIX:-${MYSQL_ENV_AWS_BUCKET_PREFIX}}
DB_USER=${DB_USER:-${MYSQL_ENV_DB_USER}}
DB_PASS=${DB_PASS:-${MYSQL_ENV_DB_PASS}}
DB_NAME=${DB_NAME:-${MYSQL_ENV_DB_NAME}}
DB_HOST=${DB_HOST:-${MYSQL_ENV_DB_HOST}}
ALL_DATABASES=${ALL_DATABASES}

if [ "${AWS_BUCKET}" == "" ]; then
echo "Missing AWS_BUCKET env variable"
exit 1
fi

if [ "${AWS_BUCKET_PREFIX}" == "" ]; then
echo "Missing AWS_BUCKET_PREFIX env variable"
exit 1
fi

if [[ ${DB_USER} == "" ]]; then
echo "Missing DB_USER env variable"
exit 1
Expand All @@ -18,14 +33,22 @@ if [[ ${DB_HOST} == "" ]]; then
echo "Missing DB_HOST env variable"
exit 1
fi



if [[ ${ALL_DATABASES} == "" ]]; then
if [[ ${DB_NAME} == "" ]]; then
echo "Missing DB_NAME env variable"
exit 1
fi
mysql --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" "$@" "${DB_NAME}" < /mysqldump/"${DB_NAME}".sql
cd /mysqldump
aws s3 cp s3://$AWS_BUCKET/$AWS_BUCKET_PREFIX/$(date +"%Y")/$(date +"%m")/$(date +"%d")/"${DB_NAME}".sql.gz .
gunzip *
mysql --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" "$@" "${DB_NAME}" < ./"${DB_NAME}".sql
else
cd /mysqldump
aws s3 cp - s3://$AWS_BUCKET/$AWS_BUCKET_PREFIX/$(date +"%Y")/$(date +"%m")/$(date +"%d")/ . --recursive
gunzip *
databases=`for f in *.sql; do
printf '%s\n' "${f%.sql}"
done`
Expand Down
7 changes: 0 additions & 7 deletions k8s/mysqldump/transporter.configmap.yaml

This file was deleted.

44 changes: 0 additions & 44 deletions k8s/mysqldump/transporter.scheduledjob.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions k8s/mysqldump/transporter.secret.yaml

This file was deleted.