linux中的同步命令rsync

1、
在网上查找了很多rsync的用法,总结出一条可用的语句如下:
/usr/bin/rsync -vzrtopg --delete /****/resFolder -e 'ssh -p 8855' [email protected].*.*:/****/desFolder
意为:把源服务器上的resFolder的文件夹,同步到目标服务器上。

2、
用rsync命令有个限制,必须两台服务器都装了rsync工具。
如果没有的话,安装步骤如下:
下载地址:http://samba.anu.edu.au/rsync/

(1)安装

  # tar zxvf rsync-3.0.5.tar.gz
  # ./configure --prefix=/usr/local/rsync
  # make && make install

(2)添加配置文件

  添加/etc/rsyncd.conf文件,文件内容如下:
  
log file = /var/log/rsyncd.log  #日志位置
pid file = /var/run/rsyncd.pid  #进程号存放位置
lock file = /var/run/rsync.lock  #锁文件存放位置

uid = root   #守护进程的用户权限
gid = root 

#port=873 #rsync使用的端口,默认873

#hosts allow = 192.168.1.2   #全局允许通过的IP地址

max connections = 5 # 客户端最大连接数目

[back]  # 要同步的模块名
path = /back     #要同步的目录
comment = source  #
ignore errors     #忽略IO错误
read only = no    # no客户端可上传文件,yes只读
write only = no   # no客户端可下载文件,yes不能下载
#list = yes       #是否提供资源列表
auth users = back_root  #登陆系统使用的用户名,没有默认为匿名。
hosts allow = 192.168.1.3 #本模块允许通过的IP地址
hosts deny = 192.168.1.4    #禁止主机IP
secrets file=/etc/rsync.pass  #密码文件存放的位置

(3)配置密码文件

  密码文件为配置文件中所写的文件/etc/rsync.pass格式为

账户:密码

(4)修改配置文件和密码文件权限为600

# chmod 600 /etc/rsyncd.conf
# chmod 600 /etc/rsync.pass

(5)启动守护进程

# rsync --daemon

可以通过以下两条命令查看进程是否存在
ps -aux |grep rsync
netstat -an |grep 873

(6)结束

以上是复制的,来自http://wuyizhaizhu.blog.163.com/blog/static/1151518692010725381632/
比较靠谱。
如果启动进程时报错了,肯定是配置文件有写错的地方。仔细检查一下吧。着急是木有用滴。



3、如果想在同步的文件夹中,忽略掉其中的某个文件夹或文件的话,用--exclude文件建议如下:
新建一个txt文档,比如exclude.txt,里面写上需要忽略的内容。如下:
aaa
bbb
ccc/aa.txt
ddd/bb.xml

然后rsync的执行语句如下:
/usr/bin/rsync -vzrtopg --delete --exclude-from="/****/exclude.txt" /****/resFolder -e 'ssh -p 8855' [email protected].*.*:/****/desFolder



总结:
比较好使。比scp强大。

猜你喜欢

转载自from-null.iteye.com/blog/1841613
今日推荐