Docker封装Xtrabackup镜像实现备份
percona-xtrabackup-24-2.4.24-1.el7.x86_64.rpm
percona-xtrabackup-80-8.0.28-21.1.el7.x86_64.rpm
############mysql5.7############
镜像封装
这里以centos:7.8.2003作为基础镜像。
新建目录
mkdir -p /opt/centos7.8_xtrabackup
最终目录结构如下:
./
├── dockerfile
└── percona-xtrabackup-24-2.4.24-1.el7.x86_64.rpm
dockerfile
FROM centos:7.8.2003
ADD percona-xtrabackup-24-2.4.24-1.el7.x86_64.rpm/
RUN yum install -y /percona-xtrabackup-24-2.4.24-1.el7.x86_64.rpm && yum clean all && rm -rf /percona-xtrabackup-24-2.4.24-1.el7.x86_64.rpm
生成镜像
docker build -t centos7.8_xtrabackup57:v1 .
运行镜像
docker run -it -d \
name xtrabackup8 \
--restart=always \
-e TZ=Asia/Shanghai \
-v /mnt/backup:/backup \
-v /home/data:/data \
centos7.8_xtrabackup:v1
docker exec -it centos7.8_xtrabackup /bin/bash
执行以下命令
5.7
innobackupex --user=root --password=12456 --port=3306 --host=192.168.31.250 --socket=/data/mysql/data/mysqld.sock --datadir=/data/mysql/data --stream=tar /backup |gzip>/backup/mysql.tar.gz
docker exec -i ceb96b813392 mysqldump --single-transaction --databases apollo-portal> /mnt/sqlbak/bak/apollo-portal$evday.sql
############mysql5.7############
############mysql8.0############
镜像封装
mkdir -p /opt/centos7.8_xtrabackup
最终目录结构如下:
./
├── dockerfile
└── percona-xtrabackup-80-8.0.28-21.1.el7.x86_64.rpm
dockerfile
FROM centos:7.8.2003
ADD percona-xtrabackup-80-8.0.28-21.1.el7.x86_64.rpm /
RUN yum install -y /percona-xtrabackup-80-8.0.28-21.1.el7.x86_64.rpm && yum clean all && rm -rf /percona-xtrabackup-80-8.0.28-21.1.el7.x86_64.rpm
生成镜像
docker build -t centos7.8_xtrabackup8:v1 .
运行镜像
docker run -it -d \
--name=xtrabackup8 \
--restart=always \
-e TZ=Asia/Shanghai \
-v /mnt/dbdata/mysql/data/8/data/:/var/lib/mysql \
-v /mnt/newsqlbak/bak/:/mnt/newsqlbak/bak/ \
centos7.8_xtrabackup8:v1
docker exec -it xtrabackup8 /bin/bash
执行以下命令
docker exec -i xtrabackup8 xtrabackup --host=172.16.35.159 --port=9000 --user=root --password=Ylkj@2021 --backup --target-dir=/mnt/newsqlbak/bak/bak_$(date "+%Y%m%d%H%M%S") --no-server-version-check
############mysql8.0############
评论区