みなさんどうもitobyです。
「rsyncのinclude,excludeの謎」です。
■rsyncのinclude,excludeの謎
srcフォルダからdstフォルダにファイルをrsyncしたい。
構造は以下のような感じ。
[root@centos79 WORK]# pwd
/WORK
[root@centos79 WORK]# ll -la
合計 0
drwxr-xr-x. 4 root root 28 1月 28 09:20 .
dr-xr-xr-x. 18 root root 236 1月 28 09:20 ..
drwxr-xr-x. 2 root root 6 1月 28 09:20 dst
drwxr-xr-x. 3 root root 111 1月 28 09:21 src
[root@centos79 WORK]#
[root@centos79 WORK]# ll -la src/
合計 0
drwxr-xr-x. 3 root root 111 1月 28 09:21 .
drwxr-xr-x. 4 root root 28 1月 28 09:20 ..
-rw-r--r--. 1 root root 0 1月 28 09:21 .bash
-rw-r--r--. 1 root root 0 1月 28 09:21 .htaccess
-rw-r--r--. 1 root root 0 1月 28 09:21 .htpasswd
-rw-r--r--. 1 root root 0 1月 28 09:21 .ssh
drwxr-xr-x. 3 root root 116 1月 28 09:29 a
-rw-r--r--. 1 root root 0 1月 28 09:21 index.html
-rw-r--r--. 1 root root 0 1月 28 09:21 page01.html
[root@centos79 WORK]# ll -la src/a
合計 0
drwxr-xr-x. 3 root root 116 1月 28 09:29 .
drwxr-xr-x. 3 root root 111 1月 28 09:21 ..
-rw-r--r--. 1 root root 0 1月 28 09:29 .bash
-rw-r--r--. 1 root root 0 1月 28 09:29 .htaccess
-rw-r--r--. 1 root root 0 1月 28 09:28 .htpasswd
-rw-r--r--. 1 root root 0 1月 28 09:29 .ssh
-rw-r--r--. 1 root root 0 1月 28 09:28 a-index.html
-rw-r--r--. 1 root root 0 1月 28 09:28 a-page01.html
drwxr-xr-x. 2 root root 6 1月 28 09:29 aa
[root@centos79 WORK]# ll -la src/a/aa
合計 0
drwxr-xr-x. 2 root root 6 1月 28 09:29 .
drwxr-xr-x. 3 root root 116 1月 28 09:29 ..
[root@centos79 WORK]#
[root@centos79 WORK]# ll -la dst/
合計 0
drwxr-xr-x. 2 root root 6 1月 28 09:20 .
drwxr-xr-x. 4 root root 28 1月 28 09:20 ..
[root@centos79 WORK]#
この中で、「.ssh」「.bash」はrsyncしたくない。
ぐぐると「--include="*/"」も入れるようなこと書いてあるけどそれだとうまくいかなかった。
※ここが謎勝手なイメージだけど、includeつけたらそれしか持って行かない感じがしちゃうけどそんなことないみたい。
rsyncのman見るとフィルタールールに?(/以外の文字列)というのがあるから「?,?」とかできそうだけど
これもダメだった。
rsyncのinclude、excludeは以下のようにすればいい。
[root@centos79 WORK]# rsync -rlv --dry-run --include=".htaccess" --include=".htpasswd" --exclude=".*" src/ dst/
sending incremental file list
.htaccess
.htpasswd
index.html
page01.html
a/
a/.htaccess
a/.htpasswd
a/a-index.html
a/a-page01.html
a/aa/
sent 458 bytes received 48 bytes 1,012.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)
[root@centos79 WORK]#
ちゃんとフォルダも持ってかれるし、要らんファイルは持ってかれない。
しょうもないけど久しぶりに技術的なこと書いた。
間違ってたら指摘してください。
続きを読む