標籤:shell
#/bin/bash
BackuPath=/opt/backup/
WebPath=/usr/local/apache2/htdocs/
DATE=`date +%Y%m%d`
WebBakFIle=web${DATE}.tar.bz2
DBFile=DB${DATE}.tar.bz2
DBuser=‘root‘
DBpassword=‘123‘
FTPserver=192.168.1.107
FtpTargetPath=‘ftp/backup‘
cd $WebPath
pwd
tar jcf $WebBakFIle * | mv $WebBakFIle $BackuPath
for db in ` mysql -u$DBuser -p$DBpassword -B -N -e ‘show databases;‘ `
do
mysqldump -u$DBuser -p$DBpassword --single-transaction $db > ${db}.sql
done
for sqlfile in `ls -l | grep ".sql" | awk ‘{print $8}‘`
do
tar jcf $DBFile $sqlfile | mv $DBFile $BackuPath
done
cd $BackuPath
pwd
ftp -v -n $FTPserver << END
user lbx qwe123
bin
cd $FtpTargetPath
ls -l
put $DBFile
put $WebBakFIle
bye
END
檔案被成功備份:650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/4D/56/wKiom1RPrLegsJB1AAOgZMO02CM727.jpg" title="2014-10-28 22:47:52 的螢幕.png" alt="wKiom1RPrLegsJB1AAOgZMO02CM727.jpg" />
每晚淩晨4點自動備份:
[[email protected] opt]# crontab -l
0 4 * * * bash /opt/echo.sh
本文出自 “龍愛雪琪” 部落格,請務必保留此出處http://dragon123.blog.51cto.com/9152073/1569011
使用shell備份網站和資料庫