Linux 网站目录和MySQL备份并上传FTP

SH文件下载:backup-template

 

#!/bin/bash
MYSQL_USER=root
MYSQL_PASS=
FTP_USER=
FTP_PASS=
FTP_IP=
FTP_backup=backup
WEB_DATA=/home/wwwroot

DataBakName=Data_$(date +”%Y%m%d”).tar.gz
WebBakName=Web_$(date +”%Y%m%d”).tar.gz
OldData=Data_$(date -d -3day +”%Y%m%d”).tar.gz
OldWeb=Web_$(date -d -3day +”%Y%m%d”).tar.gz

rm -rf /home/backup/Data_$(date -d -3day +”%Y%m%d”).tar.gz /home/backup/Web_$(date -d -3day +”%Y%m%d”).tar.gz
cd /home/backup

for db in `/usr/local/mysql/bin/mysql -u$MYSQL_USER -p$MYSQL_PASS -B -N -e ‘SHOW DATABASES’ | xargs`; do
(/usr/local/mysql/bin/mysqldump -u$MYSQL_USER -p$MYSQL_PASS ${db} | gzip -9 – > ${db}.sql.gz)
done

tar zcPf /home/backup/$DataBakName /home/backup/*.sql.gz
rm -rf /home/backup/*.sql.gz

tar zcf /home/backup/$WebBakName $WEB_DATA
ftp -v -n $FTP_IP << END
user $FTP_USER $FTP_PASS
type binary
cd $FTP_backup
delete $OldData
delete $OldWeb
put $DataBakName
put $WebBakName
bye
END

发表评论

电子邮件地址不会被公开。 必填项已用*标注