本地和異地ftp傳輸備份腳本

本地採用12小時一備同時上傳異地
            
'文件備份目錄建立auto_bak,我放在/usr/local/目錄下  
          
[root@localhost local]#mkdir auto_bak            
[root@localhost local]#cd auto_bak            
            
'編寫備份腳本            
[root@localhost auto_bak]#vi auto_bak_db.sh            
            
   #!/bin/sh            
   #delete old file            
   rm -rf /usr/local/auto_bak/dbname*            
               
   #backup the datebase file to               
   /usr/local/mysql/bin/mysqldump -u 90sec admin dbname >/usr/local/auto_bak/dbname.sql            
               
   #ftp the file to 192.168.0.1            
   #login in Ftp server and transfer the file            
     ftp -i -n <<end            
     open 192.168.0.1           
     user ftp admin            
               
     #turn to local directory            
     lcd /usr/local/auto_bak/            
               
     #transfer the file and add time lable            
     put /usr/local/auto_bak/dbname.sql dbname`date -d today +"20%y-%m-%d"~"%H:%M"`.sql            
     quit            
     end            
             
'添加權限             
[root@localhost auto_bak]#chmod +x auto_bak_db.sh             
            
2、使用crontab定時執行auto_bak_db.sh            
[root@localhost local]#crontab -u root -e            
  #每12小時備份一次,並記錄到日誌            
  0 */12 * * *  /usr/local/auto_bak/auto_bak_db.sh 1>/usr/local/auto_bak/auto_bak_db.log 2>&1            
mysql

相關文章
相關標籤/搜索