diff --git a/build-image/mysql/Dockerfile b/build-image/mysql/Dockerfile new file mode 100644 index 0000000..1b9d2ae --- /dev/null +++ b/build-image/mysql/Dockerfile @@ -0,0 +1,16 @@ +FROM ubuntu:22.04 + +LABEL MAINTAINER='beaconfire' + +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 && \ + ./aws/install && \ + curl "https://seethingx-pkg.oss-cn-beijing.aliyuncs.com/mysqldump-8.0.35-glibc2.17-x86_64.tgz" -o "mysqldump.tgz" && \ + tar xf mysqldump.tgz -C /usr/local && \ + rm -rf aws awscliv2.zip mysqldump.tgz + +ENV PATH=$PATH:/usr/local/mysqldump/bin HOST="" PORT="" PASSWORD="" +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 new file mode 100755 index 0000000..3cf7292 --- /dev/null +++ b/build-image/mysql/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +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/history/ +else + echo "Backup to failed" + exit 1 +fi \ No newline at end of file