2017-04-10 77 views
1

我的目錄和文件看起來像這樣複雜的rsync過濾(包括和不包括)

/1.txt 
/2.txt 
/3.txt 
/20170407_000000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 
/20170407_120000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 
/20170408_000000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 
/20170408_120000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 
/20170409_000000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 
/20170409_120000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 
/20170410_000000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 
/20170410_120000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 
/20170411_000000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 
/20170411_120000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 
/20170412_000000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 
/20170412_120000 
    /config 
     file1.txt 
    /logs 
     file1.txt 
    /nav 
     file1.txt 
    /schedule 
     file1.txt 
     file2.txt 
     file3.txt 
    /soh 
     file1.txt 
    /tracks 
     file1.txt 

我只想要複製的20170409 _ * /日程,20170410 _ * /日程,20170411 _ * /日程文件夾和內容。

這主要作品:

rsync -avhr --progress --include="/20170409_*/schedule/" --include="/20170410_*/schedule/" --include="/20170411_*/schedule/" --exclude="/*/*" /source/dateTimeDirectories/ /destination/dateTimeDirectories/ 

然而,這也複製了以下內容:

1.txt 
2.txt 
3.txt 
20170407_000000/ 
20170407_120000/ 
20170408_000000/ 
20170408_120000/ 
... 
20170412_000000/ 
20170412_120000/ 

我如何省略了文件,我還沒有包括dateTimeFolders,只得到dateTimeFolder的日程文件夾我已包括在內?

回答

1

如果我正確理解這種情況,則需要將選項--prune-empty-dirs(簡稱爲-m)添加到您的命令中。這些目錄與排除子項的排除規則不匹配,所以它們在默認情況下被複制。 -m可以防止這種情況發生。如果要防止複製其他文件,則必須爲它們添加特定的排除規則。例如,文件1.txt2.txt等可以被--exclude=/*.txt排除。總而言之,你的命令應該看起來如下:

rsync -avhr \ 
    --progress \ 
    --prune-empty-dirs \ 
    --include="/20170409_*/schedule/" \ 
    --include="/20170410_*/schedule/" \ 
    --include="/20170411_*/schedule/" \ 
    --exclude="/*.txt" \ 
    --exclude="/*/*" \ 
    /source/dateTimeDirectories/ \ 
    /destination/dateTimeDirectories/ 
+0

你先生是凡人中的神!實際上是 – lr100

+0

。在真實環境中測試我發現了一些更多的問題。我已經更新了上面的解釋。我們將非常感謝您的幫助。 – lr100

+0

@ lr100我已經更新了我的答案,以處理源根目錄中的* .txt文件。 – Dario