rsyncの具体的な同期パラメータの使用紹介

5512 ワード

四rsyncの具体的なパラメータの使用
4.1 Rsync同期ファイルとディレクトリの同期を指定する
テストのデモ:
1複数のファイルとディレクトリを同期させる
パラメータ:--files-from
--files-from="/tmp/list.txt"
[root@zabbix-server mh.com]# cat/tmp/list.txt
scripts
plus
e/action/
以上がディレクトリです
[root@zabbix-server mh.com]#/usr/bin/rsync -avrz--files-from="/tmp/list.txt"/home/wwwroot/mh.com/  [email protected]::mhttongbu3--password-file=/etc/passwd.txt
sending incremental file list
e/
e/action/
e/action/2.php
e/action/23.php
e/action/3.php
plus/
plus/4.php
plus/5.php
scripts/
scripts/.js
scripts/1.js
scripts/2.js
scripts/3.js
scripts/4.js
scripts/5.js
sent 753 bytes received 233 bytes  1972.00bytes/sec
total size is 59 speedup is 0.06
 
ファイルとディレクトリを同時にファイルリストに書き込んで同期する
[root@zabbix-server mh.com]# cat/tmp/list.txt
scripts
plus
e/action/
21.html
230.html
c.html
ヒント:ファイルリストは*.html形式のファイル名をサポートしていません
[root@zabbix-server mh.com]#/usr/bin/rsync -avrz--files-from="/tmp/list.txt"/home/wwwroot/mh.com/  [email protected]::mhttongbu3--password-file=/etc/passwd.txt
 
sending incremental file list
21.html
230.html
c.html
e/
e/action/
e/action/2.php
e/action/23.php
e/action/3.php
plus/
plus/4.php
plus/5.php
scripts/
scripts/.js
scripts/1.js
scripts/2.js
scripts/3.js
scripts/4.js
scripts/5.js
 
sent 931 bytes received 290 bytes  814.00bytes/sec
total size is 65 speedup is 0.05
 
4.2 rsyncは、--includeパラメータと--excludeパラメータを使用して、指定されたディレクトリを同期させ、--excludeディレクトリを後ろに配置します.
プレゼンテーション:
パラメータ:--include結合パラメータ-exclude
plusとscriptsの2つのディレクトリを同期したいだけで、他のは同期しません.
[root@zabbix-server mh.com]#/usr/bin/rsync -avrz --include "plus/"--include "scripts"--exclude "/*"/home/wwwroot/mh.com/ [email protected]::mhttongbu3 --password-file=/etc/passwd.txt
sending incremental file list
./
plus/
plus/4.php
plus/5.php
scripts/
scripts/.js
scripts/1.js
scripts/2.js
scripts/3.js
scripts/4.js
scripts/5.js
sent 533 bytes received 171 bytes  469.33bytes/sec
total size is 38 speedup is 0.05
説明:
–include「plus/」–include「scripts/」–include」には、同期するディレクトリが含まれています.–excludeには、他の非同期ディレクトリが含まれています.「*」で指定します.
--exclude'/*--includeが同期したディレクトリのほか、他のディレクトリを除外
/home/wwwroot/mh.com/ローカルで同期するディレクトリを指し、
[email protected]::mhttongbu 3は、リモート・サーバで指定されたディレクトリを指します.
ローカルディレクトリをリモートサーバで指定したディレクトリに同期
mhttongbu 3はモジュール名tongbu_user同期ユーザ
 
4.3パラメータ--exclude-from
--exclude-fromとは、それらのファイルとディレクトリを同期しないことを意味します.
プレゼンテーション1:
/usr/bin/rsync -avrz--exclude-from="/tmp/list.txt1" /home/wwwroot/mh.com/  [email protected]::mhttongbu3--password-file=/etc/passwd.txt
sending incremental file list
./
21.html
230.html
30.html
c.html
lsd.html
q.html
test00001.html
test001
1/
13/
a34325/
adnc/
e/

 
[root@zabbix-server mh.com]# cat /tmp/list.txt1
plus
e/action
scripts

 
プレゼンテーション2:
[root@VM_82_178_centos 1]# cat /tmp/file.list 
txt01
txt02/1
jianwei01
test001

[root@VM_82_178_centos 1]# rsync -avzh  --password-file=/tmp/pass.txt --exclude-from=/tmp/file.list [email protected]::backup /data/www/jianwei.com
receiving incremental file list
txt02/
txt02/2/
sent 87 bytes  received 124 bytes  422.00 bytes/sec
total size is 42  speedup is 0.20

4.4パラメータ--delete--exclude={a..f}.txt
クライアント:rsync-avz--delete--exclude={a..f}.txt/tmp/[email protected]::backup--password-file=/etc/rsync.passwordパスワードファイルを指定すると、インタフェースにデジタルメッセージが表示されません.自動的に操作を完了できます.同時に--exclude={a..f}.txtは、クライアントデータがサービス側データを完全に置き換えることを防止するために、サービス側を保持するコンテンツを選択的に排除するものである.
 4.5パラメータ--excludeの説明
rsyncクライアントが同期する必要のないファイルまたはディレクトリを除外
同期を必要としないファイル名の除外、同期を必要としないディレクトリの除外
[root@VM_82_178_centos txt01]# ll /data/www/jianwei.com/*
-rw-r--r-- 1 root root    7 Aug 22 16:42 /data/www/jianwei.com/jianwei01
-rw-r--r-- 1 root root    6 Aug 22 16:16 /data/www/jianwei.com/test001
/data/www/jianwei.com/txt01:
total 0
/data/www/jianwei.com/txt02:
total 8
-rw-r--r-- 1 root root  7 Aug 22 16:45 jianwei02
-rw-r--r-- 1 root root 23 Aug 22 16:48 jianwei03
[root@VM_82_178_centos txt01]# 

   :
[root@VM_82_178_centos txt01]# rsync -avzh  --password-file=/tmp/pass.txt --exclude "jianwei01" --exclude=txt01 --exclude "txt02/jianwei02" --exclude=txt02/jianwei03 [email protected]::backup /data/www/jianwei.com
receiving incremental file list

sent 92 bytes  received 88 bytes  120.00 bytes/sec
total size is 6  speedup is 0.03
[root@VM_82_178_centos txt01]#

プレゼンテーション2:txt 01ディレクトリを同期し、jianwei 01ファイルを同期せず、txt 02/jianwei 02ファイルを同期せず、txt 02/jianwei 03ファイルを同期しない
[root@VM_82_178_centos txt01]# rsync -avzh  --password-file=/tmp/pass.txt --exclude=jianwei01  --exclude "txt02/jianwei02" --exclude=txt02/jianwei03 [email protected]::backup /data/www/jianwei.com
receiving incremental file list
txt01/
txt01/1.txt
txt01/2.txt
txt01/3.txt
sent 150 bytes  received 265 bytes  276.67 bytes/sec
total size is 6  speedup is 0.01
[root@VM_82_178_centos txt01]#

5.rsyncパラメータの説明
http://blog.csdn.net/stevenprime/article/details/7601261