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