docker 中MySQL数据库备份导出,定时备份
1.查看docker以启动的容器[root@master mysql_file_backup]# docker psCONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES22...
1.查看docker以启动的容器
[root@master mysql_file_backup]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
223b8db4d620 mysql:5.6 "docker-entrypoint.s…" 19 minutes ago Up 19 minutes 0.0.0.0:3306->3306/tcp mymysql
[root@master mysql_file_backup]#
2.docker 启动mysql命令
[root@master mysql_file_backup]# docker run -p 3306:3306 --name mymysql02 -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
[root@master mysql_file_backup]# docker run -p 3306:3306 --name mymysql01 -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
921e49c04cfa02212d8a1a262111f9d70d8373749b28df8bea1ed7a480548134
[root@master mysql_file_backup]#
[root@master mysql_file_backup]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
921e49c04cfa mysql:5.6 "docker-entrypoint.s…" 6 seconds ago Up 5 seconds 0.0.0.0:3306->3306/tcp mymysql01
[root@master mysql_file_backup]#
[root@master mysql_file_backup]# docker stop 921e49c04cfa
921e49c04cfa
[root@master mysql_file_backup]#
[root@master mysql_file_backup]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@master mysql_file_backup]#
[root@master mysql_file_backup]# docker run -p 3306:3306 --name mymysql02 -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
c2372697670d82cef11bf24f6a7c647d64d5fae29d9178999390698deb9e3290
[root@master mysql_file_backup]#
[root@master mysql_file_backup]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c2372697670d mysql:5.6 "docker-entrypoint.s…" 8 seconds ago Up 8 seconds 0.0.0.0:3306->3306/tcp mymysql02
[root@master mysql_file_backup]#
[root@master mysql_file_backup]#
[root@master mysql_file_backup]# docker exec -it c2372697670d mysqldump -uroot -p123456 test200321 > /root/mysql_file_backup/mysqlbakup_test200321.sql
[root@master mysql_file_backup]# ll
总用量 8
-rw-r--r--. 1 root root 2680 3月 31 22:43 mysqlbakup_test200321.sql
-rw-r--r--. 1 root root 2680 3月 31 22:06 test200321_backup.sql
[root@master mysql_file_backup]#
-----------------
(如果 要关闭 指定容器)
docker stop CONTAINER ID #CONTAINER ID 是容器的 id编号
-----------------------------
3.导出数据库
[root@master mysql_file_backup]# docker exec -it c2372697670d mysqldump -uroot -p123456 test200321 > /root/mysql_file_backup/mysqlbakup_test200321.sql
c2372697670d # 是 CONTAINER ID(容器的ID)
-uroot # root是 mysql用户名
-p123456 # 123456是 mysql密码;
test200321 #是mysql的 数据库
/root/mysql_file_backup/mysqlbackup_test200321.sql # 备份到宿主机的 /root/mysql_file_backup/目录下的mysqlbakup_test200321.sql的文件中;
4定时备份;(如下,还未验证)
查看链接https://blog.csdn.net/wsyzxss/article/details/79495940
把 上述 链接中的 脚本 内容改下,编辑一个文件dataBaseName.sh
内容如下
#!/bin/bash
docker exec -it c2372697670d mysqldump -uroot -p123456 test200321 > /root/mysql_file_backup/mysqlbakup_test200321.sql/dataBaseName1_$(date +%Y%m%d_%H%M%S).sql.gz
4.2添加可执行权限;chmod +x dataBaseName.sh
然后 ,rcontab -e 中 ,添加 定时任务;
查看链接https://blog.csdn.net/wsyzxss/article/details/79495940
参考:https://blog.csdn.net/qq_37674858/article/details/80082903
更多推荐
所有评论(0)