阳光越强烈
阴影就越是深邃

RSYNC增量备份

RSYNC增量备份,需要2台VPS,让他们之间做数据同步。比如,我们的网站放在VPS A,那么A就是网站服务器端;用另一台VPS B做增量备份,那么B就是备份服务器端。

这里说的只是单纯的B为A备份,A与B均为linux相同系统。

首先下载网站VPS端和备份VPS客户端配置文件:网站服务器端配置文件|备份服务器端配置文件

服务器端设定

首先,将下载回来的服务器端配置文件上传至VPS的/etc目录中,然后对相关文件修改设定(也可以先修改再上传)

1:修改/etc/rsyncd/rsyncd.conf 共5处

# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help

# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid
port = 873
address = 1.2.3.4 #修改为网站服务器端的IP
#uid = nobody
#gid = nobody
uid = root
gid = root

use chroot = yes
read only = yes

#limit access to private LANs
#hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0
#hosts deny=*
hosts allow=2.3.4.5 #修改为备份服务器端的IP
max connections = 3
motd file = /etc/rsyncd/rsyncd.motd

#This will give you a separate log file
log file = /home/wwwlogs/rsync.log

#This will log every file transferred – up to 85,000+ per user, per sync
#transfer logging = yes

log format = %t %a %m %f %b
syslog facility = local3
timeout = 300

   [taiyangtaWEB]  #修改成自己喜欢的名字
path = /home/wwwroot   #修改成你要备份的目录,如改为/home/wwwroot/blog,就是只备份blog目录的东西
list=yes
ignore errors
auth users = taiyangtaWEB  #修改成自己喜欢的名字
secrets file = /etc/rsyncd/rsyncd.secrets

 2:修改/etc/rsyncd/rsyncd.secrets用户及密码,并设置权限(此用户及密码请自行指定)
   chmod 600 /etc/rsyncd/rsyncd.secrets
3:在服务器上运行RSYNC
  /usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf

客户端设定

将下载的备份服务器端配置文件上传至备份VPS的/root目录,然后对相关文件设定 欢迎访问,鄙视采集!
1:修改/root/pass文件,填入密码设定与服务器端一致,并赋予权限。
chmod 600 /root/pass
2:修改/root/rs.sh文件,设定rsync路径与服务器端一致,并赋予权限。
rsync -avzP --delete --password-file=/root/pass taiyangtaWEB@1.2.3.4::taiyangtaWEB /home/wwwroot
#上面第一个taiyangtaWEB为网站服务器端/etc/rsyncd/rsyncd.secrets中用户名
#1.2.3.4为网站服务器端IP
#第二个taiyangtaWEB为网站服务器端设定的自定义命名
#最后的/home/wwwroot为同步的网站目录
然后,设定权限  chmod +x /root/rs.sh

完成以上设定后,我们可以测试下这个脚本是否正常工作,ssh登陆备份服务器端,手动运行/root/rs.sh,检测是否正常同步成功。如果一切正常,我们再用cron实现每日自动运行这个脚本。

添加以下任务

00 01 * * * /root/AutoBackupToFtp.sh

任务的时间请自行设定,上面代码中的00 01,就是凌晨1点开始运行备份脚本,尽量选择网站访客最少的时间段,如下半夜。

 

赞(0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址