Created
April 2, 2018 20:31
-
-
Save nuved/2baf9b2f30892bd851e96209a3cd099c to your computer and use it in GitHub Desktop.
create a backup from mysql with innobackupex with docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#vi /etc/backup-my.cnf | |
[client] | |
user=backup | |
password=password | |
[mysqld] | |
#socket=/var/run/mysqld/mysqld.sock | |
host=127.0.0.1 | |
datadir=/var/lib/mysql | |
innodb_log_group_home_dir=/var/lib/mysql | |
#GRANT CREATE TABLESPACE, RELOAD, PROCESS, SUPER, LOCK TABLES, REPLICATION CLIENT ON . TO 'backup'@'localhost'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:16.04 | |
MAINTAINER Novid Agha Hasani <novid.aghahasani@gmail.com> | |
RUN apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A | |
RUN echo "deb http://repo.percona.com/apt xenial main" >> /etc/apt/sources.list && \ | |
apt-get update | |
RUN apt-get install -y --allow-unauthenticated percona-xtrabackup-24 tzdata | |
ENV TZ=Asia/Tehran | |
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone | |
VOLUME /var/backup/mysql | |
CMD cdate=$(date +%Y-%m-%d-%H-%M) && mkdir -p "/target/$cdate" && cd "/target/$cdate" && innobackupex --defaults-file=/etc/backup-my.cnf \ | |
--no-lock \ | |
--no-timestamp \ | |
--host=127.0.0.1 \ | |
--password=password \ | |
--user=backup \ | |
--port=3306 \ | |
--use-memory=1G \ | |
--parallel=4 \ | |
. \ | |
> ../backup-progress.log 2>&1 && innobackupex --apply-log . > ../backup-progress.log 2>&1 && cd .. && tar -czf "$cdate.tgz" /target/$cdate 2> /dev/null && rm -rf /target/$cdate | |
#crontab -e | |
# 48 * * * * docker run --volumes-from mysql -v /etc/backup-my.cnf:/etc/backup-my.cnf -v /backup:/target --net=container:mysql --rm xtrabackup 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment