rsync 數(shù)據(jù)同步使用詳解
更新時(shí)間:2008年09月17日 13:09:57 作者:
rsync 是很強(qiáng)大的同步工具 本地遠(yuǎn)程皆宜
不少project都提供 http ftp rsync 等mirror方式
rsync官方主頁是 http://samba.anu.edu.au/rsync/
rsync(d)服務(wù)端啟動(dòng)兩種方式
1.daemon 2.xinetd inetd
啟動(dòng)后綁在 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
}
配置 注意設(shè)置讀寫權(quán)限屬主
% 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 一行一個(gè)用戶 用戶名:密碼 格式
使用
rsync -auvPz --progress dir1 dir2
rsync -ztruvoglpD --progress dir1 dir2
rsync -ztruvoglpD --progress dir1/ dir2
rsync -ztruvoglpD --progress dir1/file1 dir2
如果不想包含某個(gè)目錄/文件可以設(shè)置--exclude
遠(yuǎn)程使用
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 ./
同步時(shí)注意注意 / 最后的問題
不放/ 則目錄名也包含mirror
放 / 則只有目錄里面的東西mirror了
rsync -ztruvoglp --progress user@1.1.1.1::module/path ./
為了腳本調(diào)用方便 還可以調(diào)用 --password-file 同樣注意屬主權(quán)限
也可以設(shè)置環(huán)境變量RSYNC_PASSWORD=訪問含用戶認(rèn)證的rsync
1.daemon 2.xinetd inetd
啟動(dòng)后綁在 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
}
配置 注意設(shè)置讀寫權(quán)限屬主
% 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 一行一個(gè)用戶 用戶名:密碼 格式
使用
rsync -auvPz --progress dir1 dir2
rsync -ztruvoglpD --progress dir1 dir2
rsync -ztruvoglpD --progress dir1/ dir2
rsync -ztruvoglpD --progress dir1/file1 dir2
如果不想包含某個(gè)目錄/文件可以設(shè)置--exclude
遠(yuǎn)程使用
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 ./
同步時(shí)注意注意 / 最后的問題
不放/ 則目錄名也包含mirror
放 / 則只有目錄里面的東西mirror了
rsync -ztruvoglp --progress user@1.1.1.1::module/path ./
為了腳本調(diào)用方便 還可以調(diào)用 --password-file 同樣注意屬主權(quán)限
也可以設(shè)置環(huán)境變量RSYNC_PASSWORD=訪問含用戶認(rèn)證的rsync
相關(guān)文章
Linux下9種優(yōu)秀的代碼比對(duì)工具推薦小結(jié)
這篇文章主要介紹了Linux下9種優(yōu)秀的代碼比對(duì)工具推薦小結(jié),不僅有命令行工具,還有 GUI 界面工具,讓你輕松進(jìn)行代碼比對(duì),感興趣的可以一起來了解一下2020-06-06centos下安裝redis服務(wù)詳細(xì)節(jié)介紹
這篇文章主要介紹了 centos安裝redis 服務(wù)的資料,這里對(duì)安裝步驟進(jìn)行了詳細(xì)的介紹,具有參考價(jià)值,有需要的小伙伴可以參考下2016-11-11Linux系統(tǒng)下如何實(shí)現(xiàn)修改主機(jī)名
這篇文章主要介紹了Linux系統(tǒng)下如何實(shí)現(xiàn)修改主機(jī)名問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02如何關(guān)閉http Methods中的Trace 提高安全意識(shí)
在配置文件http.conf 添加 TraceEnable off 即可關(guān)閉2013-02-02