diff --git a/build-image/mongo/Dockerfile b/build-image/mongo/Dockerfile new file mode 100644 index 0000000..7e5b897 --- /dev/null +++ b/build-image/mongo/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 "mongodump.tgz" && \ + tar xf mongodump.tgz -C /usr/local && \ + rm -rf aws awscliv2.zip mongodump.tgz + +ENV PATH=$PATH:/usr/local/mongodump/bin DATABASES="" 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/mongo/entrypoint.sh b/build-image/mongo/entrypoint.sh new file mode 100755 index 0000000..1ebd9dd --- /dev/null +++ b/build-image/mongo/entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +datetime=`date +%Y%m%d%H` + +dbs=($DATABASES) + +for db in "${dbs[@]}" +do + mongodump --host ${HOST} --port ${PORT} --authenticationDatabase admin -u root -p ${PASSWORD} --db $db --gzip --archive=${db}.tgz + if (($?==0));then + aws s3 cp ${db}.tgz s3://bfs-pkg-storage/mongodb/backup/${datetime}/ + else + echo "Backup to failed" + exit 1 + fi + +done