首页 > 代码库 > 本地和异地ftp传输备份脚本

本地和异地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             
            
二、使用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            

本文出自 “断了的军刀” 博客,请务必保留此出处http://90sec.blog.51cto.com/7404127/1576227

本地和异地ftp传输备份脚本