複製資料

rsync -avhW --no-compress --info=progress2 src/ dst/

rsyncd 設定檔 (server)

rsyncd.conf

pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsync.log

[nas]
path = /shares/rsync/nas
uid = root
#gid = share
gid = root
read only = no
list = yes
auth users = root
secrets file = /etc/rsyncd.secrets

rsyncd.secrets

root:PASSWORD

備份指令,在要備份資料的伺服器上執行,192.168.50.35 為 rsync server。

參數說明

RSYNC_PASSWORD="PASSWORD" rsync --delete --archive /home root@192.168.50.35::nas

選項與參數:

rsync [-avrlptgoD] [-e ssh] [user@host:/dir] [/local/path]

Rsync over SSH 範例

rsync -a --progress --delete -e "ssh -i /home/user/.ssh/id_rsa" /home/CSNA2016/backup [email protected]:/home/user

標題

rsync -a --exclude 'file.txt' src_directory/ dst_directory/
rsync -a --exclude 'dir1' src_directory/ dst_directory/
rsync -a --exclude 'dir1/*' src_directory/ dst_directory/
rsync -a --exclude 'file1.txt' --exclude 'dir1/*' --exclude 'dir2' src_directory/ dst_directory/
rsync -a --exclude={'file1.txt','dir1/*','dir2'} src_directory/ dst_directory/
rsync -a --exclude-from='exclude-file.txt' src_directory/ dst_directory/
rsync -a --exclude '*.jpg*' src_directory/ dst_directory/
rsync -a -m --include='*.jpg' --include='*/' --exclude='*' src_directory/ dst_directory/
find src_directory/ -name "*.jpg" -printf %P\\0\\n | rsync -a --files-from=- src_directory/ dst_directory/

參考