Simple Web Site Backup script
The code is as follows |
Copy Code |
#!/bin/bash #backup Database Mypw=cactiez newtime=$ (Date +%y%m%d) if [-d/var/www/backup/];then Mysqldump-u ROOT-P$MYPW DB >/var/www/backup/$newtime-database.sql Else mkdir/var/www/backup/ Mysqldump-u ROOT-P$MYPW DB >/var/www/backup/$newtime-database.sql Fi tar-zcvf/var/www/backup/$newtime-www.tar.gz/var/www/ find/var/www/backup/-mtime +4-exec rm-rf {}; |
There is also a more advanced automatic backup site/database/binding meter information/Automatic upload FTP script
This script features:
1. Pure zip compression, 1-9 can adjust the compression rate
2. The whole VPS backup, restore convenient, very suitable for the station group
3. Add compressed password, you can set your own
4. Add the binding meter information pseudo static compression, prevent pseudo static to lose
5. Please ensure that there is a backup directory in the home directory, if not please perform mkdir/home/backup
6. Restore DATABASE Please refer to: Import Database method
Last modified: August 25, 2012
CentOS Installation Zip
Yum Install zip
Debian installation Zip
Apt-get Install Zip
Download edit
Wget-c http://www.***.com/soft/beifen.sh
VI beifen.sh
Edit annotations only where you need to modify them
"Script Start"
The code is as follows |
Copy Code |
#!/bin/bash #下面的参数是你要修改的 Mysql_user=root #mysql用户名 Mysql_pass=mysql Password #mysql密码 FTP_USER=FTP User name #ftp用户名 ftp_pass=ftp Password #ftp密码 Ftp_ip=ftp Address #ftp地址 Ftp_backup=ftp directory #ftp上存放备份文件的目录, this should be built on their own FTP web_data=/home/wwwroot/#要备份的网站数据 web_bangmi=/usr/local/nginx/conf/#要备份的绑米信息 Web_mulu=/home/backup #备份文件存放目录 Web_mima=zhujima #备份时候的密码 Web_yasuolv=1 #压缩率 1-9 If the VPS does not have a zip, please install zip #上面是你要修改的地方
#删除淘宝客缓存, belong to a custom setting. Can operate on its own #rm-rf/home/wwwroot/1.com/apicache/*
#定义数据库的名字和旧数据库的名字 databakname=data_$ (date + "%y%m%d"). zip #定义数据库名字 webbakname=web_$ (date +%y%m%d). zip #定义备份网站名字 bangmi=bangmi_$ (date +%y%m%d). zip #定义绑米备份名字
olddata=data_$ (date-d -5day + "%y%m%d"). zip #定义5天前数据库名字 oldweb=web_$ (date-d -5day + "%y%m%d"). zip #定义5天前网站名字 bangmishan=bangmi_$ (date-d -5day + "%y%m%d"). zip #定义5天前绑米名字
#删除本地3天前的数据 RM-RF $WEB _mulu/data_$ (date-d -3day + "%y%m%d"). zip $WEB _mulu/web_$ (date-d -3day + "%y%m%d"). zip $WEB _mulu/bangmi_$ ( date-d -3day + "%y%m%d"). zip
#导出全部数据库 CD $WEB _mulu /usr/local/mysql/bin/mysqldump-u$mysql_user-p$mysql_pass--all-databases > $ (date + "%y%m%d"). sql
#压缩数据库文件为一个文件 Zip-r-$WEB _yasuolv-p $WEB _mima $DataBakName $WEB _mulu/*.sql RM-RF $WEB _mulu/*.sql
#压缩网站数据 CD $WEB _data Zip-r-$WEB _yasuolv-p $WEB _mima $WebBakName./* MV $WebBakName $WEB _mulu/$WebBakName CD $WEB _mulu
#压缩绑米信息 CD $WEB _bangmi #进入绑米目录 Zip-r-$WEB _yasuolv-p $WEB _mima $BANGMI./* MV $BANGMI $WEB _mulu/$BANGMI #上传到FTP空间, delete data from FTP space 5 days ago CD $WEB _mulu #进入备份目录 FTP-V-N $FTP _ip << End User $FTP _user $FTP _pass Type binary CD $FTP _backup Delete $BANGMIshan Delete $OldData Delete $OldWeb Put $DataBakName Put $WebBakName Put $BANGMI Bye End Add permissions, write timed execution chmod 777/root/beifen.sh Crontab-e * * * */root/beifen.sh |