注意: rsync命令使用中, 若是源參數的末尾有斜線, 只會複製指定目錄的內容, 而不復制目錄自己, 沒有斜線, 則會複製目錄自己, 包括目錄.
Examples:
rsync -r /mydata/data /bachups
#會把目錄data直接同步至/bakups目錄中
rsync -r /mydata/data/ /backups
#會把目錄data/中的內容至/backups目錄中html
馬哥linux視頻linux
王曉冬/Rsync 12種故障排查及思路(http://www.javashuo.com/article/p-ufmoxbew-kk.html)vim
John_ABC/Linux-Rsync服務器/客戶端搭建實戰(http://www.javashuo.com/article/p-ksdjfxpj-kk.html)bash
SHIHUC/rsync配置中的auth error,一個隱祕的錯誤(http://www.javashuo.com/article/p-mqhcqkqj-kh.html)服務器
rysnc -- a fast, versatile, remote and local file-copying toolssh
前提: SRC和DEST端必須都安裝rsynctcp
yum install rsync -y
ide
其餘選項:測試
# 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
Please dry run first for testui
rsync -nv SRC... DEST # Options: -n, --dry-run # perform a trail run with no changes mode -v, --verbose
rsync -avz --progress SRC... DEST
# Pull rsync -avz -e ssh --progress USER@HOST:SRC... DEST # Push rsync -avz -e ssh --progress SRC... USER@HOST:DEST
Port: 873/tcp
注意: 關閉該死的seinux !!!
安裝超級守護進程xinetd
yum install xinetd -y
爲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 # 用戶密碼的存放位置
配置密碼文件/etc/rsyncd.passwd
vim /etc/rsyncd.passwd
USERNAME:PASSWORD
chmod 600 /etc/rsyncd.passwd
配置服務可以啓動
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]
配置密碼文件
vim /etc/rsyncd.passwd
PASSWORD
chmod 600 /etc/rsyncd.passwd
指定密碼文件rsync傳輸文件
# E.G. pull rsync -avz --progress \ --password-file=/etc/rsyncd.passwd \ zak@192.168.0.117::mydata/test /tmp
😄 Oh Yeah!