我使用rsync將文件從家用計算機移動到服務器。以下是我用來傳輸和更新僅包含grep + glob的文件的目錄的命令。我從下面顯示的目錄結構的toplevel/
目錄執行該命令。Rsync include/exclude在python子進程中不起作用
rsync -r --progress --include='**201609*/***' --exclude='*' -avzh files/ [email protected]:/user/files
這裏就是我的家文件的工作目錄的文件結構如下:
- toplevel
- items
- files
- 20160315
- 20160910
- dir1
- really_cool_file1
- 20160911
- dir2
這工作得很好,並在[email protected]:/user/files
文件結構是一樣的我家的電腦上。
我寫了一個python腳本來做到這一點,它不起作用。它也通過files/20160315
轉移,這不是我想要的。
#!/usr/bin/env python3
import os
from subprocess import run
os.chdir("toplevel")
command_run = ["rsync", "-r",
"--progress",
"--include='**201609*/***'",
"--exclude='*'",
"-avzh",
"files/", "[email protected]:/user/files"]
run(command_run, shell=False, check=True)
這是怎麼回事?當command_run
是一個字符串時,我遇到了同樣的問題,並且我通過shell=True
將它傳遞給了subprocess.run()
。
的報價是外殼,而不是rsync的運行的。 –
是的,單引號被剝離。試試''--include = ** 201609 */***「'。 – tdelaney