当前位置: 首页 > 图文教程 > 服务器 > Linux服务器 > rsync 数据同步使用详解

Linux服务器
Solaris基本审计和报告工具使用攻略
优化Linux服务器硬盘性能的七个实用技巧
解决Linux服务器下误删除文件的操作
Linux操作系统下SOFTETHER服务器使用方法
使用SMC实现Solaris10服务器角色管理(下)
Linux环境架设Samba服务器 实现网络互访
Linux下安装RPM和TAR管理软件包的方法
如何建立一个安全的 Linux服务器
在Linux上实现DB2双机HA完整方案
教您在LINUX中架设代理服务器
使用Linux系统架设安全的网关
解决Linux服务器下误删除文件问题!
高效配置Linux代理服务器 Squid介绍
基于Linux的虚拟主机搭建
Linux 服务器的远程控制技术及实战
教程:如何最快搭建LINUX服务器集群
Apache安装配置优化
Linux实战之NFS服务器客户端配置
LAMP服务器就环境的建立
基于Linux的FTP服务器权限管理

Linux服务器 中的 rsync 数据同步使用详解


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-04   浏览: 70 ::
收藏到网摘: n/a

rsync 是很强大的同步工具 本地远程皆宜 不少project都提供 http ftp rsync 等mirror方式 rsync官方主页是 http://samba.anu.edu.au/rsync/ rsync(d)服务端启动两种方式
1.daemon 2.xinetd inetd
启动后绑在 TCP/873 端口
% cat /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
配置 注意设置读写权限属主
% cat /etc/rsyncd.conf
motd file = /var/log/rsync/welcome.msg
pid file = /var/log/rsync/rsyncd.pid
lock file = /var/log/rsync/rsync.lock
log file = /var/log/rsync/rsyncd.log
[rsyncwww]
comment = rsync www
path = /var/www/
use chroot = no
max connections = 4
read only = false
list = true
uid = nobody
gid = nobody
auth users = wwwuser
secrets file = /etc/rsyncd.secrets
hosts allow = 1.1.1.1,2.2.2.2
hosts deny = 0.0.0.0/0
ignore errors = yes
transfer logging = yes
log format = "%a %f %l"
#log format = "%o %h [%a] %m (%u) %f %l"
[rsyncroot]
comment = rsync root
path = /
use chroot = no
max connections = 4
read only = true
#read only = false
list = true
uid = root
gid = root
auth users = rootuser
secrets file = /etc/rsyncd.secrets
hosts allow = 1.1.1.1,2.2.2.2
hosts deny = 0.0.0.0/0
ignore errors = yes
transfer logging = yes
log format = "%a %f %l"

rsyncd.secrets 一行一个用户 用户名:密码 格式
使用
rsync -auvPz --progress dir1 dir2
rsync -ztruvoglpD --progress dir1 dir2
rsync -ztruvoglpD --progress dir1/ dir2
rsync -ztruvoglpD --progress dir1/file1 dir2
如果不想包含某个目录/文件可以设置--exclude
远程使用
rsync 1.1.1.1:: 只列list
rsync [email protected]::
rsync [email protected]::module
rsync [email protected]::module/path
如果没有配置rsync server 可以通过 ssh 方式使用
rsync -e ssh -auvPz 1.1.1.1:/etc ./
同步时注意注意 / 最后的问题
不放/ 则目录名也包含mirror
放 / 则只有目录里面的东西mirror了
rsync -ztruvoglp --progress [email protected]::module/path ./
为了脚本调用方便 还可以调用 --password-file 同样注意属主权限
也可以设置环境变量RSYNC_PASSWORD=访问含用户认证的rsync