rsync 數(shù)據(jù)同步使用詳解
更新時間:2008年09月17日 13:09:57 作者:
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:: 只列l(wèi)ist
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 同樣注意屬主權限
也可以設置環(huán)境變量RSYNC_PASSWORD=訪問含用戶認證的rsync
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:: 只列l(wèi)ist
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 同樣注意屬主權限
也可以設置環(huán)境變量RSYNC_PASSWORD=訪問含用戶認證的rsync
相關文章
如何關閉http Methods中的Trace 提高安全意識
在配置文件http.conf 添加 TraceEnable off 即可關閉2013-02-02