linux 上传备份脚本,Linux下自动备份网站数据并上传的脚本代码

原创内容,转载请注明出处: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.

9b5e825fbcbab892b44f2dc82590bf2f.png

Linux下自动备份网站数据并上传的脚本代码

4c85db8eab9e5ed45b93843956ec2f5f.png

Linux下自动备份网站数据并上传的脚本代码

sicnature ---------------------------------------------------------------------

Your current IP address is: 121.231.173.188

Your IP address location: 江苏省常州市溧阳市电信

Your IP address country and region: 中国

d9840db1de5c066b3143a36b83ba0940.png

Your current browser is:

c55e3eff36f0c380a04e3e5ffee3bbca.png

Your current system is:

mac.png

Original content, please indicate the source:

同福客栈论坛 | 蟒蛇科普 | 海南乡情论坛 | JiaYu Blog

sicnature ---------------------------------------------------------------------

Welcome to reprint. Please indicate the source https://www.myzhenai.com.cn/post/1819.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值