使用Rsync推与拉方式:同步Web网页数据

来源:转载

Ø 思路

更新:管理服务器(主机shenxiang62) 使用rsync推送数据到(主机shenxiang61)即可 备份:管理服务器(主机shenxiang62) 使用rsync从主机(shenxiang61)拉入数据到本地 对此,shenxiang61 为rsync服务端 shenxiang62为客户端


1、主机shenxiang61配置rsync服务安装,并使用xinetd守护进程启动 [[email protected] ~]# yum install -y xinetd
[[email protected] ~]# vim /etc/xinetd.d/rsync
service rsync
{
disable = no#把yes改为no
flags= IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = –daemon
log_on_failure+= USERID
}添加配置文件/etc/rsyncd.conf [[email protected] ~]# vim /etc/rsyncd.conf
[[email protected] ~]# cat !$
Ø因为这里文件都是apache服务来使用;所以读写用户设为apache
cat /etc/rsyncd.conf
uid = apache
gid = apache
use chroot = no
max conections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsync.log
[webdata]
path = /www/web/
ignore errors
read only = no
list = yes
hosts allow = 192.168.1.62
auth users = xuegod
secrets file = /etc/rsync.password虚拟用户认正文件

注意: #文件格式:[用户:密码] #认证文件权限要为600


[[email protected] ~]# vim /etc/rsync.password
[[email protected] ~]# cat !$
cat /etc/rsync.password
xuegod:xg123456
[[email protected] ~]# chmod 600 !$
chmod 600 /etc/rsync.password
[[email protected] ~]# ll !$
ll /etc/rsync.password
–rw——- 1 root root 16 Feb 18 00:12 /etc/rsync.password重启并检查监听端口 [[email protected] ~]# /etc/init.d/xinetd restart
[[email protected] ~]# lsof -i :873
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
xinetd26469 root6uIPv6542070t0TCP *:rsync (LISTEN)
2、主机shenxiang62配置更新rsync [[email protected] ~]# yum install -y rsync创建免交互密码文件 [[email protected] ~]# vim /etc/rsync.webpwd
[[email protected] ~]# cat !$
cat /etc/rsync.webpwd
xg123456
[[email protected] ~]# chmod 600 !$
chmod 600 /etc/rsync.webpwd
[[email protected] ~]# ll !$
ll /etc/rsync.webpwd
-rw——- 1 root root 9 Feb 18 11:46 /etc/rsync.webpwd
3、备份网页数据到主机shenxiang62

Ø 原理:使用rsync拉pull数据同步方式 Ø 执行动作:主机shenxiang62

创建备份存放目录/data/webdata,并备份到本地 [[email protected] ~]# mkdir /data/webdata备份测试(Rsync拉Pull) [[email protected] ~]# rsync -avz [email protected]::webdata –password-file=/etc/rsync.webpwd /data/webdata/
......省略
uc_server/view/default/pm_send.htm
uc_server/view/default/pm_view.htm
uc_server/view/default/templates.lang.php
uc_server/view/default/user_avatar.htm
sent 80375 bytesreceived 12036146 bytes4846608.40 bytes/sec
total size is 28106599speedup is 2.32查看备份数据 [[email protected] ~]# ll /data/webdata/
total 116
-rw-r–r–1 apache apache 2739 Feb 17 22:08 admin.php
drwxr-xr-x 11 apache apache 4096 Feb 17 22:08 api
-rw-r–r–1 apache apache727 Feb 17 22:08 api.php
drwxr-xr-x2 apache apache 4096 Feb 17 22:08 archiver
drwxr-xr-x2 apache apache 4096 Feb 17 22:45 config
......省略编写备份脚本Web网页脚本 [[email protected] ~]# cd /data_bak/
[[email protected] data_bak]# vim webbak.sh
[[email protected] data_bak]# cat !$
cat webbak.sh
#!/bin/bash
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
webdata='/data_bak/webdata/'
webdaemon=webdata
webuser=xuegod
webhost='192.168.1.61'
mysqlhost='192.168.1.222'
webpwd='/etc/rsync.webpwd'
time=$(date +"%Y%m%d")
rsync -avz [email protected]$webhost::$webdaemon --password-file=$webpwd /data/webdata/$time_bak /
&& echo "NFS server webdata ${time} backup success!!" >>/data_bak/bak.log && find /data/webdata -mtime +8 |xargs rm -rf添加计划任务 [[email protected] data_bak]# echo “30 3 * * * root /bin/bash /data_bak/webbak.sh” >> /etc/crontab
[[email protected] data_bak]# tail /etc/crontab
# .—————- minute (0 – 59)
# |.————- hour (0 – 23)
# ||.———- day of month (1 – 31)
# |||.——- month (1 – 12) OR jan,feb,mar,apr …
# ||||.—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |||||
# ***** user-name command to be executed
30 4 * * * root /bin/bash /data_bak/webbak.sh
4、更新(恢复)主机shenxiang61上的网页数据

Ø 原理:rsync使用推push数据同步方式 Ø 执行动作:主机shenxiang62

清空主机shenxiang61上的网页数据 [[email protected] ~]# cp -r /www/web/ /www/web.bak
[[email protected] ~]# rm -rf /www/web/*
[[email protected] ~]# ll /www/web
total 0更新测试(Rsync推Push) [[email protected] ~]# rsync -avz –delete /data/webdata/ [email protected]::webdata –password-file=/etc/rsync.webpwd
......省略
uc_server/view/default/pm_nav.htm
uc_server/view/default/pm_send.htm
uc_server/view/default/pm_view.htm
uc_server/view/default/templates.lang.php
uc_server/view/default/user_avatar.htm
sent 12036078 bytesreceived 80324 bytes1615520.27 bytes/sec
total size is 28106599speedup is 2.32查看更新数据 [[email protected] ~]# ll /www/web
total 116
-rw-r–r–1 apache apache 2739 Feb 17 22:08 admin.php
drwxr-xr-x 11 apache apache 4096 Feb 17 22:08 api
-rw-r–r–1 apache apache727 Feb 17 22:08 api.php
drwxr-xr-x2 apache apache 4096 Feb 17 22:08 archiver
drwxr-xr-x2 apache apache 4096 Feb 17 22:45 config
-rw-r–r–1 apache apache922 Feb 17 22:08 connect.php
-rw-r–r–1 apache apache253 Feb 17 22:08 cp.php
......省略

分享给朋友:
您可能感兴趣的文章:
随机阅读: