FC2ブログ

rsyncのinclude,excludeの謎

みなさんどうも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]#

ちゃんとフォルダも持ってかれるし、要らんファイルは持ってかれない。

しょうもないけど久しぶりに技術的なこと書いた。

間違ってたら指摘してください。

追記(2021/1/31)※ここが謎の部分
ネットによく出てるやつはexcludeで*してるから
ディレクトリだけ同期するために最初に入れてるみたいだということに気づいた気がする。
けど、そもそもinclude,excludeで定義しててそれ以外が入るのは何故なのか。
仕様だからなんだろうけど…

関連記事
スポンサーサイト



コメントの投稿

非公開コメント

カウンター
プロフィール

itoby

Author:itoby
サラリーマン業以外でお金がほしい。

別で電柱もアップしてます。
今日の電柱
#こちらは最近停滞気味…

New!
マインクラフトのサーバー建ててます。
是非遊びに来てください。
https://tobibuta.pgw.jp

最新記事
リンク
カテゴリ
スポンサードリンク
検索フォーム
問い合わせはこちらから

名前:
メール:
件名:
本文:

Amazon.co.jp