update mysql backup
parent
2bf380260c
commit
ecc2856f6b
|
@ -2,6 +2,10 @@ FROM ubuntu:22.04
|
||||||
|
|
||||||
LABEL MAINTAINER='beaconfire'
|
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 && \
|
RUN apt update && apt install -y curl unzip && \
|
||||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
|
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
|
||||||
unzip awscliv2.zip && \
|
unzip awscliv2.zip && \
|
||||||
|
@ -10,7 +14,7 @@ RUN apt update && apt install -y curl unzip && \
|
||||||
tar xf mysqldump.tgz -C /usr/local && \
|
tar xf mysqldump.tgz -C /usr/local && \
|
||||||
rm -rf aws awscliv2.zip mysqldump.tgz
|
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
|
COPY entrypoint.sh /usr/local/bin
|
||||||
|
|
||||||
CMD [ "/usr/local/bin/entrypoint.sh" ]
|
CMD [ "/usr/local/bin/entrypoint.sh" ]
|
|
@ -2,10 +2,19 @@
|
||||||
|
|
||||||
datetime=`date +%Y%m%d%H`
|
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
|
mkdir -p ~/.aws
|
||||||
if (($?==0));then
|
|
||||||
aws s3 cp bfs-application-${datetime}.sql s3://bfs-pkg-storage/mysql/backup/
|
echo -ne "[default]\naws_access_key_id = ${AWS_ACCESS_KEY}\naws_secret_access_key = ${AWS_SECRET_KEY}\n" > ~/.aws/credentials
|
||||||
else
|
|
||||||
|
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"
|
echo "Backup to failed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
done
|
Loading…
Reference in New Issue