美文网首页
【第5期】docker: linux 定时备份docker 下的

【第5期】docker: linux 定时备份docker 下的

作者: 村中一少 | 来源:发表于2020-04-20 17:04 被阅读0次

原创文章,转载请注明原文章地址,谢谢!

1)创建备份目录db_bak

image

2) 编辑备份脚本db_bak.sh

 #!/bin/bash
sysdate=$(date +"%Y-%m-%d%H%M%S")
docker exec -i mymysql mysqldump -R -uroot -p123456 test
 --default-character-set=utf8 --hex-blob  
 > /root/db_bak/test_${sysdate}.sql

3)编辑定时器 vim /etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
​
# For details see man 4 crontabs
​
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
# * * * * * /usr/bin/env > /tmp/env.txt
​
0 2 * * * root /root/db_bak/db_bak.sh

坑1:****crontab提示command not found

image

坑2 :the crontab the input device is not a TTY

image

坑3:中文乱码

show variables like 'character%';

看到文件大小不是0k了,但是打开后

image

解决:创建容器的时候设置字符集

https://blog.csdn.net/jiegemena/article/details/80062653

docker run -p 3306:3306 --restart always --name mymysql  -e MYSQL_ROOT_PASSWORD=123456 -d  mysql:5.6 
--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
image

说明:关注微信公众号【村中一少】,回复“电子书”按照提示信息获取对应书籍目录序号,如回复【1】,即可获得电子书【研磨设计模式.陈臣.王斌.扫描版.pdf】下载地址,所有电子均为免费。

这些电子书仅仅用于学习,如果喜欢请购买正版图书!请支持原版作者!

相关文章

网友评论

      本文标题:【第5期】docker: linux 定时备份docker 下的

      本文链接:https://www.haomeiwen.com/subject/hhadihtx.html