原创内容,转载请注明出处:https://www.myzhenai.com.cn/post/1819.html https://www.myzhenai.com/thread-16228-1-1.html
因为我使用的是linux服务器,所以平时备份的时候我都是采取先备份数据库,然后再用FTP工具备份附件数据的方法进行备份到本地,但是如果你有另外一台服务器做为备份服务器的话,可以采用以下的备份和上传的脚本来进行备份.Backup.sh是备份脚本,Upload.sh是上传脚本.
*注*:在使用脚本之前,请针对你的服务器环境对脚本做适当的修改,比如路径,密码,用户名等.切记勿直接使用本脚本代码,以免造成数据丢失.
Backup.sh内的代码:
# !/bin/bash # This is the Linux website data automatic backup script. https://www.myzhenai.com.cn https://www.haikou-china.com https://www.myzhenai.com.cn https://jiayu.mybabya.com ac=`date +%Y` bc=`date +%m` cc=`date +%d` # Get the current date mkdir /var/Backup cd /var/ cp -ar html/www Backup/ # The copy web site directory to the backup directory mysqlcheck -Ao -uroot -pPassword mysqldump -u root -pPassword DatabaseName |gzip > Backup/www"_"$ac"_"$bc"_"$cc.sql.gz # Remove the database cache, optimizing database, backup database. "Password" is your database administrator password, "DatabaseName" is that you need to backup the database name. cd Backup tar -czvf www"_"$ac"_"$bc"_"$cc.tar.gz */ cd /var/ rm -rf Backup/www rar a www"_"$ac"_"$bc"_"$cc.zip Backup/* -pPassword # Rar compression commands, Password is a compressed package decompression password. #cp -ar www"_"$ac"_"$bc"_"$cc.zip html/www/ # OR sh Upload.sh # Upload.sh is automatically upload script. rm -rf Backup rm -rf www"_"$ac"_"$bc"_"$cc.zip cd ..
Upload.sh内的代码:
#!/usr/bin/expect # This is the Linux website data automatic backup script. https://www.myzhenai.com.cn https://www.haikou-china.com https://www.myzhenai.com.cn https://jiayu.mybabya.com spawn scp -P Port /var/*.zip root@110.110.110.110:/var/Backup/ # If your backup server connection to the SSH is the default port, can be like writing order. spawn scp -P /var/*.zip root@110.110.110.110:/var/Backup/ expect "password:*" send "Password\r" # Password\r where Password is the backup SSH connection to server password.
sicnature ---------------------------------------------------------------------
I P 地 址: 18.191.68.112
区 域 位 置: 美国俄亥俄
系 统 信 息:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普 | 海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://myzhenai.com.cn/post/1819.html
3条评论
怎么放那个谷歌广告呀
Quick Adsense
安装这个插件就可以了,可以展现广告
如果需要定时备份,请把脚本丢进cron里.
不过不建议这么做,因为备份网站数据所需要的时间是根据你网站数据的多少来决定的.
假如网站数据多,数据库文件大的话,在压缩的过程中使用时间比较长.