docker快速搭建mysql容器定時備份資料到磁碟

來源:互聯網
上載者:User

標籤:apt   container   data   資料   step   host   www   5.7   dock   

step 1 建立dockfile

localhost:5.7.17 jack$ vi DockerfileFROM mysql:5.7.17MAINTAINER Jack.heENV TZ="Asia/Shanghai" LANG=zh_CN.UTF-8RUN cp /usr/share/zoneinfo/$TZ /etc/localtime && apt-get update && apt-get install -y vim && apt-get install -y cron

step 2 建立image並推送到私服

docker build -t 10.10.101.199:5000/ab-mysql-backup:5.7.17 .docker push 10.10.101.199:5000/ab-mysql-backup:5.7.17

step 3 建立啟動指令碼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:/root 10.10.101.199:5000/ab-mysql-backup:5.7.17echo "===============docker container started.==============="

step 4 建立Database Backup指令碼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 為需要備份伺服器ip以及mysql使用者名稱和密碼/usr/bin/mysqldump -h192.168.2.22 -uroot -p12345678 testdb > /root/sql/testdb_$currentTime.sqlecho "backup databases end !!!"

step 5 啟動容器並建立crontab任務

[[email protected] mysqlbackup]$sh /export/mysql/mysqlbackup/run.sh[[email protected]-ip199 mysqlbackup]$ docker exec -it mysqlbackup bash[email protected]:/# crontab -l*/1 * * * * sh /root/backup.sh[email protected]:/#service cron start #啟動定時任務

 

  

docker快速搭建mysql容器定時備份資料到磁碟

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.