rsync命令

rsync命令

😄 Written by Zak Zhu

注意: rsync命令使用中, 若是源參數的末尾有斜線, 只會複製指定目錄的內容, 而不復制目錄自己, 沒有斜線, 則會複製目錄自己, 包括目錄.
Examples:
rsync -r /mydata/data /bachups #會把目錄data直接同步至/bakups目錄中
rsync -r /mydata/data/ /backups #會把目錄data/中的內容至/backups目錄中html

參考

rsync命令

rysnc -- a fast, versatile, remote and local file-copying toolssh

安裝

前提: SRC和DEST端必須都安裝rsynctcp

yum install rsync -yide

工做模式

其餘選項:測試

# Options:
	-q, --quiet			# suppress non-error messages
	-c, --checksum
	-e ssh				# use ssh protocl to transfer
	-a, --archive		# archive mode; equals -rlptgoD 
	-z, --compress
	--stats				# give some file-transfer stats
	--progress			# show progress during transfer
	--password-file=FILE
Dry-run Mode

Please dry run first for testui

rsync -nv SRC... DEST
# Options:
	-n, --dry-run		# perform a trail run with no changes mode
	-v, --verbose

0

1


Local Mode
rsync -avz --progress SRC... DEST

2


Remote Mode
# Pull
rsync -avz -e ssh --progress USER@HOST:SRC... DEST
# Push
rsync -avz -e ssh --progress SRC... USER@HOST:DEST

3


Daemon Mode

Port: 873/tcp

服務端配置

注意: 關閉該死的seinux !!!

  1. 安裝超級守護進程xinetd

    yum install xinetd -y

  2. 爲rsync提供配置文件

    man 5 rsyncd.conf

    # 查看rsyncd.conf配置裏每一個屬性含義

    以及查看EXAMPLES部分了解基礎配置例子

    vim /etc/rsyncd.conf

    定義一個全局配置和多個rsync共享配置

    # Global Settings

    uid = nobody

    gid = nobody

    use chroot = no # 是否禁錮用戶家目錄

    max connections = 10 # 最大鏈接數, 10已經很是大

    strict modes = yes # 是否徹底檢查

    pid file = /var/run/rsyncd.pid

    log file = /var/log/rsyncd.log

    # Directory to be synced

    [SYNCED_NAME] # 模塊名映射成下面path

    path = /PATH/TO/SOME_DIR

    ignore errors = yes

    read only = yes

    # This parameter determines whether clients will be able to upload files or not. If 「read only」 is true then any attempted uploads will fail. If 「read only」 is false then uploads will be possible if file permissions on the daemon side allow them. The default is for all modules to be read only.

    write only = no

    # This parameter determines whether clients will be able to download files or not. If 「write only」 is true then any attempted downloads will fail. If 「write only」 is false then downloads will be possible if file permissions on the daemon side allow them. The default is for this parameter to be disabled.

    hosts allow = 192.168.0.0/24

    hosts deny = *

    list = false

    # This parameter determines if this module should be listed when the client asks for a listing of available modules. By setting this to false you can create hidden modules. The default is for modules to be listable.

    uid = USERNAME # 表示以哪一個用戶身份去獲取文件, 最好不要用root

    gid = GROUPNAME # 表示以哪一個屬組身份去獲取文件, 最好不要用root

    auth users = USERNAME # 容許的用戶

    secrets file = /etc/rsyncd.passwd # 用戶密碼的存放位置

  3. 配置密碼文件/etc/rsyncd.passwd

    vim /etc/rsyncd.passwd

    USERNAME:PASSWORD

    chmod 600 /etc/rsyncd.passwd

  4. 配置服務可以啓動

    chkconfig rsync on

    chkconfig xinetd on

    service xinetd restart

客戶端測試
# Pull
rsync -avz --progress USER@HOST::SRC... DEST
rsync -avz --progress rsync://USER@HOST/SRC... DEST
#SRC: rsyncd.conf裏指定的共享模塊名, 即配置文件裏[SYNCED_NAME]

# Push
rsync -avz --progress SRC... USER@HOST::DEST
rsync -avz --progress SRC... rsync://USER@HOST/DEST
#DEST: rsyncd.conf裏指定的共享模塊名, 即配置文件裏[SYNCED_NAME]
  1. 配置密碼文件

    vim /etc/rsyncd.passwd

    PASSWORD

    chmod 600 /etc/rsyncd.passwd

  2. 指定密碼文件rsync傳輸文件

    # E.G. pull
    rsync -avz --progress \
    --password-file=/etc/rsyncd.passwd \
    zak@192.168.0.117::mydata/test  /tmp

    4

😄 Oh Yeah!

相關文章
相關標籤/搜索