rsyncからサブディレクトリを除外する方法は?

rsyncからサブディレクトリを除外する方法は?

私はrsync、次のようにリモートフォルダツリーを再帰的に同期するために使用します。

/folderA/a1/cache
/folderA/a1/cache/A1
/folderA/a1/cache/A2
/folderA/a1/somefolder
/folderA/a1/someotherfolder
/folderA/a2/somefolder/cache
/folderB/cache/
/folderB/b1/somefolder/cache
/folderB/b1/somefolder/yetanotherfolder/cache
/folderB/b1/somefolder/yetanotherfolder/cache/B1
/folderB/b1/somefolder/yetanotherfolder/cache/B2

フォルダツリーがどのように見えるかはわかりませんが、時間が経つと変わります。だから私がしたいのは、rsync上記の作業を再帰的に行うことです。入らないようにするフォルダ「キャッシュ」とここに含まれるすべてのサブフォルダ:

/folderA/a1
/folderA/a1/somefolder
/folderA/a1/someotherfolder
/folderA/a2/somefolder
/folderB/
/folderB/b1/somefolder
/folderB/b1/somefolder/yetanotherfolder/

どんな提案がありますか?

ベストアンサー1

--excludeあなたは旗が欲しいです。たとえば、ローカル rsync は次のようになります。

rsync -a --exclude cache/ src_folder/ target_folder/

本当に簡単です。除外ルールは、cacheツリーの名前が付けられたディレクトリと一致します。最後に、/ディレクトリと一致するように強制し、名前付きファイルを除外しないようにしますcache

パスを一致させることもできます。次のツリーが与えられたら:

a1/cache/
b1/cache/
sub/a1/cache/

--exclude a1/cache/一致a1/cachesub/a1/cache一致しませんb1/cache。そして--exclude /a1/cache/唯一の一致ですa1/cache

rsyncフィルタリングでできることははるかに多いです。 rsyncのマニュアルページで、特に「FILTER RULES」セクションと「PATTERN MATCHING RULES」セクションを見つけてください--exclude--include--filter

https://www.samba.org/ftp/rsync/rsync.html#FILTER_RULES

おすすめ記事