原创内容,转载请注明出处: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.
Linux下自动备份网站数据并上传的脚本代码
Linux下自动备份网站数据并上传的脚本代码
sicnature ---------------------------------------------------------------------
Your current IP address is: 121.231.173.188
Your IP address location: 江苏省常州市溧阳市电信
Your IP address country and region: 中国
Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普 | 海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://www.myzhenai.com.cn/post/1819.html