Ubuntu 下 MySQL 資料自執行備份

來源:互聯網
上載者:User

1.首先把計劃任務添加到列表,系統每分鐘會掃描一次工作清單,探測目前時間下是否有待執行的任務 

 
  1. /etc/crontab: 
  2. # m h dom mon dow user    command 
  3.   0 1  *   *  *   root    /home/fzw/db.sh 
  4.   0 2  *   *  *   root    /home/fzw/auto.sh 

m:分    h:時    dom: day of month    mon:月     dow: day of week    user:使用者   command:任務指令

2./home/fzw/db.sh  備份,壓縮

 
  1. mysqldump -x -u root -h 127.0.0.1 -p 123 -c --hex-blob --default-character-set=utf8 --compact --no-create-db --no-create-info --databases dbname > /home/fzw/136/136_4d`date +%Y%m%d`.sql 
  2. rar a /home/fzw/136/136_4d`date +%Y%m%d`.rar /home/fzw/136/136_4d`date +%Y%m%d`.sql 

3./home/fzw/auto.sh  同時拷貝至192.168.2.143

 
  1. #!/usr/bin/expect -f 
  2. set date [exec date +%Y%m%d] 
  3. set password 123  
  4. spawn scp /home/fzw/136/136_4d$date.rar fzwadmin@192.168.2.143:/home/fzwadmin/136/136_4d$date.rar 
  5. set timeout 300 
  6. expect "fzwadmin@192.168.2.143's password:" 
  7. send "$password\r" 
  8. expect eof 
  9. #interact 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.