Rsync include/exclude don't work in python subprocess
<p>I use rsync to move files from my home computer to a server. Here's the command that I use to transfer and update the directory of only files that contain a grep + glob. I execute this command from the <code>toplevel/</code> directory in the directory structure I show below.</p>

<pre><code> rsync -r --progress --include='**201609*/***' --exclude='*' -avzh files/ user@server.edu:/user/files
</code></pre>

<p>Here's what the file structure of the working directory on my home file looks like:</p>

<pre><code> - toplevel
      - items
      - files
        - 20160315
        - 20160910
          - dir1
            - really_cool_file1
        - 20160911
          - dir2
</code></pre>

<p>This works fine, and the file structure on <code>user@server.edu:/user/files</code> is the same as on my home computer.</p>

<hr>

<p>I wrote a python script to do this and it doesn't work. It also transfers over the <code>files/20160315</code>, which is not what I want.</p>

<pre><code> #!/usr/bin/env python3
 import os
 from subprocess import run

 os.chdir("toplevel")

 command_run = ["rsync", "-r",
           "--progress",
           "--include='**201609*/***'",
           "--exclude='*'",
           "-avzh",
           "files/", "user@server.edu:/user/files"]

 run(command_run, shell=False, check=True)
</code></pre>

<p>What's going on here? I had the same problem when <code>command_run</code> was a string, and I passed it to <code>subprocess.run()</code> with <code>shell=True</code>.</p>

<p>Some of those quotes are removed by the shell before being passed to the called process. You need to do this yourself if you call the program with the default <code>shell=False</code>. This little script will tell you what your parameters need to look like</p>

<p>test.py</p>

<pre><code>#!/usr/bin/env python3
import sys
print(sys.argv)
</code></pre>

<p>And then running with your command line</p>

<pre><code>~/tmp $ ./test.py -r --progress --include='**201609*/***' --exclude='*' -avzh files/ user@server.edu:/user/files
['./test.py', '-r', '--progress', '--include=**201609*/***', '--exclude=*', '-avzh', 'files/', 'user@server.edu:/user/files']
~/tmp $
</code></pre>

python python-3.x rsync