寫一個指令碼定時自動備份mysql到指定目錄

來源:互聯網
上載者:User

標籤:mysql   命名 自動備份 mysqldump   

執行個體:

編寫一個shell指令碼每天16:30備份mysql資料並壓縮打包(打包檔案按照當天的日期命名)放到/root/data


#cd /root#vim mysqlbackup.sh#!/bin/bashtime=`date +%Y-%m-%d`backupdir=/root/dataif [ ! -d "$backupdir" ]thenmkdir -p $backupdirfiif [ -f "$time"_all_databases.sql ]thenrm -rf "$time"_all_databases.sqlficd $backupdir/usr/bin/mysqldump -uroot -pmysql.rzrk --all-databases > "$time"_all_databases.sql/bin/tar -czf "$time"_all_databases.sql.tar.gz  "$time"_all_databases.sqlrm -rf "$time"_all_databases.sqlsed -i ‘/mysqlbackup.sh/d‘ /var/spool/cron/rootecho ‘30 16 * * *  /root/mysqlbackup.sh‘  >>  /var/spool/cron/root#chmod +x mysqlbackup.sh


注釋:

1 mysqldump --all-databases 表示備份mysql中所有的資料庫。

2 date +‘%Y-%m-%d‘ == date +%F

3 crontab -l 編輯的設定檔在/var/spool/cron下(redhat的),suse的在/var/spool/cron/tabs下


本文出自 “天道酬勤” 部落格,請務必保留此出處http://luzhi1024.blog.51cto.com/8845546/1654077

寫一個指令碼定時自動備份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.