引用链接: http://jiayu.mybabya.com/post/2923.html
因为我使用的是linux服务器,所以平时备份的时候我都是采取先备份数据库,然后再用FTP工具备份附件数据的方法进行备份到本地,但是如果你有另外一台服务器做为备份服务器的话,可以采用以下的备份和上传的脚本来进行备份.Backup.sh是备份脚本,Upload.sh是上传脚本.
*注*:在使用脚本之前,请针对你的服务器环境对脚本做适当的修改,比如路径,密码,用户名等.切记勿直接使用本脚本代码,以免造成数据丢失.
Backup.sh内的代码:
# !/bin/bash
# This is the Linux website data automatic backup script. http://www.myzhenai.com.cn http://www.haikou-china.com http://www.myzhenai.com.cn http://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. http://www.myzhenai.com.cn http://www.haikou-china.com http://www.myzhenai.com.cn http://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 ---------------------------------------------------------------------
Original content, please indicate the source:
I P 地 址: 3.129.63.252
区 域 位 置: 美国
系 统 信 息:
https://jiayu.mybabya.com/post/2923.html
Antecedents page:
蟒蛇科普|海南仙岛|海南乡情论坛|JiaYu Blog
sicnature ---------------------------------------------------------------------
如果需要定时备份,请把脚本丢进cron里.
不过不建议这么做,因为备份网站数据所需要的时间是根据你网站数据的多少来决定的.
假如网站数据多,数据库文件大的话,在压缩的过程中使用时间比较长.
这个有用,学习了。
有用,收藏了。
站长我们可以交换一下友链吗?小站链接
可以,很荣庆.