本帖最后由 米拿现’ 于 2012-12-9 21:57 编辑

#!/bin/bash


#Funciont: Backup website and mysql database


#IMPORTANT!!!Please Setting the following Values!


######~Set Directory you want to backup~######
Backup_Dir1=fanshuwo.me

######~Set MySQL UserName and password~######
MYSQL_UserName=root
MYSQL_PassWord=yourrootpassword

######~Set MySQL Database you want to backup~######
Backup_Database_Name1=fanshuwo

######~Set FTP Information~######
FTP_HostName=192.168.0.150
FTP_UserName=fanshuwo.me
FTP_PassWord=yourftppassword
FTP_BackupDir=backup

#Values Setting END!

TodayWWWBackup=www-*-$(date +"%Y%m%d").tar.gz
TodayDBBackup=db-*-$(date +"%Y%m%d").sql
OldWWWBackup=www-*-$(date -d -3day +"%Y%m%d").tar.gz
OldDBBackup=db-*-$(date -d -3day +"%Y%m%d").sql

tar zcf /home/backup/www-$Backup_Dir1-$(date +"%Y%m%d").tar.gz -C /home/wwwroot/$Backup_Dir1 –exclude=soft

/usr/local/mysql/bin/mysqldump -u$MYSQL_UserName -p$MYSQL_PassWord $Backup_Database_Name1 > /home/backup/db-$Backup_Database_Name1-$(date +"%Y%m%d").sql

rm -f /home/backup/$OldWWWBackup
rm -f /home/backup/$OldDBBackup

cd /home/backup/

lftp $FTP_HostName -u $FTP_UserName,$FTP_PassWord << EOF
cd $FTP_BackupDir
mrm $OldWWWBackup
mrm $OldDBBackup
mput $TodayWWWBackup
mput $TodayDBBackup
bye
EOF

——————–  给755的权限(chmod 755 ),结合crond 定时备份。

发表评论

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