diff --git a/build-image/mysql/Dockerfile b/build-image/mysql/Dockerfile index 1b9d2ae..63a1d98 100644 --- a/build-image/mysql/Dockerfile +++ b/build-image/mysql/Dockerfile @@ -2,6 +2,10 @@ FROM ubuntu:22.04 LABEL MAINTAINER='beaconfire' +mkdir -p ~/.aws + +echo -ne "[default]\naws_access_key_id = ${AWS_ACCESS_KEY}\naws_secret_access_key = ${AWS_SECRET_KEY}\n" > ~/.aws/credentials + RUN apt update && apt install -y curl unzip && \ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \ unzip awscliv2.zip && \ @@ -10,7 +14,7 @@ RUN apt update && apt install -y curl unzip && \ tar xf mysqldump.tgz -C /usr/local && \ rm -rf aws awscliv2.zip mysqldump.tgz -ENV PATH=$PATH:/usr/local/mysqldump/bin HOST="" PORT="" PASSWORD="" +ENV PATH=$PATH:/usr/local/mysqldump/bin DATABASES="" HOST="" PORT="" PASSWORD="" AWS_ACCESS_KEY="" AWS_SECRET_KEY="" COPY entrypoint.sh /usr/local/bin CMD [ "/usr/local/bin/entrypoint.sh" ] \ No newline at end of file diff --git a/build-image/mysql/entrypoint.sh b/build-image/mysql/entrypoint.sh index 33bccb5..79d7f6f 100755 --- a/build-image/mysql/entrypoint.sh +++ b/build-image/mysql/entrypoint.sh @@ -2,10 +2,19 @@ datetime=`date +%Y%m%d%H` -mysqldump -h ${HOST} -P ${PORT} -u backup -p${PASSWORD} --single-transaction --set-gtid-purged=OFF --all-databases > bfs-application-${datetime}.sql -if (($?==0));then - aws s3 cp bfs-application-${datetime}.sql s3://bfs-pkg-storage/mysql/backup/ -else - echo "Backup to failed" - exit 1 -fi \ No newline at end of file +mkdir -p ~/.aws + +echo -ne "[default]\naws_access_key_id = ${AWS_ACCESS_KEY}\naws_secret_access_key = ${AWS_SECRET_KEY}\n" > ~/.aws/credentials + +dbs=${DATABASES} + +for db in ${dbs[@]}; +do + mysqldump -h ${HOST} -P ${PORT} -u backup -p${PASSWORD} --single-transaction --set-gtid-purged=OFF $db > ${db}.sql + if (($?==0));then + aws s3 cp ${db}.sql s3://bfs-pkg-storage/mysql/backup/${datetime}/ + else + echo "Backup to failed" + exit 1 + fi +done \ No newline at end of file