该脚本实现如下的功能:
文件:erpbackup.sh
复制代码代码如下:
#!/bin/sh
(责任编辑:IT)#--------------------------------------------------------- # scriptname: erpbackup.sh # version: 1.0 for linux # method: backup mysqldb # author: fengzhanhai # history: create program V1.1 20110429 by Fengzhanhai UserName='root' AdminPwd='passw0rd' DbName=erp BakDir=/home/imu/db-backup/vpnback LogFile=/home/imu/db-backup/vpnback/mysqlbak.log DATE=`date +%Y%m%d%H%M` DumpFile=vpndata$DATE.sql GZDumpFile=$DumpFile.tgz FtpServer=10.19.98.235 FtpTargetPath=/erp_backup/mysql #main--------------------------------------------------------- echo $(date +"%y-%m-%d %H:%M:%S") backup begin >> $LogFile cd $BakDir #备份当天文件 /usr/local/mysql/bin/mysqldump -u$UserName -p$AdminPwd $DbName > $DumpFile echo $(date +"%y-%m-%d %H:%M:%S") Dump Done >> $LogFile #tar压缩文件 tar czvf $GZDumpFile $DumpFile >> $LogFile #rm -f $DumpFile echo $(date +"%y-%m-%d %H:%M:%S") $GZDumpFile compress done >> $LogFile #上传到ftp服务器 ftp -v -n $FtpServer << END user databack passw0rd bin cd $FtpTargetPath put $GZDumpFile bye END echo $(date +"%y-%m-%d %H:%M:%S") ftp $GZDumpFile compress done >> $LogFile rm -f $GZDumpFile #删除当前目录下7天前的文件备份文件 find $BakDir -name "vpndata*" -mtime +7 -exec rm {} \; echo $(date +"%y-%m-%d %H:%M:%S") delete old file done >> $LogFile #验证结果 ls -al $DumpFile >> $LogFile |