Docker quickly builds MySQL container to backup data to disk regularly

Source: Internet
Author: User
Tags docker run

Step 1 Create Dockfile

localhost:5.7.  - VI dockerfilefrom MySQL: 5.7.  - maintainer jack.heenv TZ="asia/shanghai"  LANG=zh_cn. utf-8cpinstallinstall -y cron

Step 2 creates an image and pushes it to a

10.10. 101.199:/ab-mysql-backup:5.7.  -  10.10. 101.199:/ab-mysql-backup:5.7.  -

Step 3 Create a startup script run.sh

$ mkdir-p/export/mysql/mysqlbackup/script/sql
vi/export/mysql/mysqlbackup/run.sh
#!/bin/BashEcho "================start Docker container...==============="Docker Run-D--restart=always--name Mysqlbackup-E mysql_root_password=12345678 -v/etc/localtime:/etc/Localtime:ro-v/export/mysql/mysqlbackup/script:/Root10.10.101.199: the/ab-mysql-backup:5.7. -Echo "===============docker Container started.==============="

Step 4 Create a database backup script backup.sh

VI/export/mysql/mysqlbackup/script/backup.SH#!/bin/Bashsource/etc/ ProfileEcho "... begin backup Databases ....."currenttime=`Date "+%y%m%d%h%m%s"`Echo 'Current Time ='$currentTime
#192.168.2.22 for the need to back up the server IP and MySQL user name and password/usr/bin/mysqldump-h192.168.2. A-uroot-p12345678 TestDB >/root/sql/Testdb_$currenttime.sqlEcho "backup databases End!!!"

Step 5 Start the container and create the crontab task

[Email protected] mysqlbackup]$sh /export/mysql/mysqlbackup/run. SH [[email protected]-ip199 mysqlbackup]$ Docker exec-it mysqlbackup bash[email protected]:/# crontab-< C6>l*/1sh /root/backup. SH [email protected]:/#service cron start #启动定时任务

Docker quickly builds MySQL container to backup data to disk regularly

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.