服务器 
首页 > 服务器 > 浏览文章

rsync 数据同步使用详解

(编辑:jimmy 日期: 2024/6/27 浏览:3 次 )
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 user@1.1.1.1::
rsync user@1.1.1.1::module
rsync user@1.1.1.1::module/path
如果没有配置rsync server 可以通过 ssh 方式使用
rsync -e ssh -auvPz 1.1.1.1:/etc ./

同步时注意注意 / 最后的问题
不放/ 则目录名也包含mirror
放 / 则只有目录里面的东西mirror了

rsync -ztruvoglp --progress user@1.1.1.1::module/path ./
为了脚本调用方便 还可以调用 --password-file 同样注意属主权限
也可以设置环境变量RSYNC_PASSWORD=访问含用户认证的rsync
上一篇:使用rsync来实现文件同步
下一篇:rsync中文手册之使用rsync实现网站镜像和备份linux第1/3页
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。