Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1915120
  • 博文数量: 498
  • 博客积分: 2078
  • 博客等级: 大尉
  • 技术积分: 1645
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-18 22:43
个人简介

安大

文章分类

全部博文(498)

文章存档

2017年(1)

2016年(2)

2015年(21)

2014年(90)

2013年(101)

2012年(267)

2011年(16)

分类: LINUX

2013-07-02 15:46:15

原文地址:rsync同步数据 作者:pspery

rsync是类unix系统下的数据镜像备份工具
 
特性
可以镜像保存整个目录树和文件系统
可以很容易做到保持原来文件的权限、时间、软硬链接等等。
第一次全部传输,此后只传送两个文件的不同部分,而不是每次都整份传送,因此速度相当快。
可以使用scp、ssh等方式来传输文件,当然也可以通过直接的socket连接,很安全

A实现
nodeA为server        nodeB为client
【nodeA】
1.安装
# tar xzvf rsync-3.0.7.tar.gz 
# cd rsync-3.0.7
# ./configure --prefix=/usr/local/rsync
# make && make install
# useradd rsyncuser
2.rsyncd.conf的配置
# mkdir /etc/rsyncd              
# touch /etc/rsyncd/rsyncd.conf         
# touch /etc/rsyncd/rsyncd.secrets       
# chmod 600 /etc/rsyncd/rsyncd.secrets  
# touch /etc/rsyncd/rsyncd.motd         
# vi /etc/rsyncd/rsyncd.conf
-----------------------------------------------------------------------

pid file = /var/run/rsyncd.pid          
port = 873                           
address = 10.18.20.32            
#uid = nobody
#gid = nobody   
uid = root                              
gid = root  
use chroot = yes                  
read only = yes                        
hosts allow=10.18.20.33/255.255.255.255
hosts deny=*                                                
max connections = 1                                           
motd file = /etc/rsyncd/rsyncd.motd                            
log file = /var/log/rsync.log                                
#transfer logging = yes
log format = %t %a %m %f %b        
syslog facility = local3           
timeout = 300             

[linux_home]         
path = /home/wangxiao/         
list=yes               
ignore errors          
auth users = rsyncuser       
secrets file = /etc/rsyncd/rsyncd.secrets
comment = wang's home 
#exclude =      
-----------------------------------------------------------------------

3.启动
# /usr/local/rsync/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf
4.停止
# kill `cat /var/run/rsyncd.pid`
5.防火墙放行
# iptables -A INPUT -p tcp -m state --state NEW  -m tcp --dport 873 -j ACCEPT

【nodeB】
1.列出rsync nodeA同步内容
# rsync  --list-only rsyncuser@10.18.20.32::
# rsync  --list-only rsyncuser@10.18.20.32::linux_home      注:查看具体要备份的文件
2.rsync client同步数据
# rsync -avzP rsyncuser@10.18.20.32::linux_home   ./ 
# rsync -avzP --delete rsyncuser@10.18.20.32::linux_home ./
注:--delete表示客户端上数据要与服务器端完全一致
# rsync -avzP --delete --password-file=/rsync.password rsyncuser@10.18.20.32::linux_home ./
# touch /rsync.password
# touch 600 /rsync.password               注:使用密码文件,就可以直接做计划任务自动同步了

B实现                

直接在client编写同步脚本rsync.sh,
server端不用做配置
#!/bin/bash
#filename:
#version:
#author:
#date:
#description:
#----------------------------------------
_list="10.18.20.32|/var/www/vhosts/tool.min-fx.jp/bin
10.18.20.32|/jhfapp/app/conf/info.cfg.xml
10.18.20.32|/jhfapp/app/conf/main.cfg.xml
10.18.20.32|/root/bin/p_test_rc4.pl"
_dir="/tmp/syncdir"

for x in $(echo $_list|grep -v '^#'|sed -e '/^$/d');do
        _info=( $(echo "$x"|awk -F'|' '{print $1,$2}') )
        _ip=$(echo ${_info[0]})
        _file=$(echo ${_info[1]})
        for i in $_file;do
                 rsync -Hxva --delete --exclude=logs/*  --exclude=*.tar.gz $_ip:$_file $_dir
        done
done

阅读(648) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~