Run Rsync from Python

Marcus picture Marcus · Aug 22, 2013 · Viewed 26.1k times · Source

I need to run an rsync command from Python. Is this possible and if so, how do I do it?

rsync -Ccavz --delete DJStatic username@website

Answer

philshem picture philshem · Aug 28, 2013

You can call a subprocess from python using the following snippet

import subprocess
subprocess.call(["ls", "-l"])

In your case, it would be something like this

subprocess.call(["rsync", "-Ccavz", "--delete","DJStatic", "username@website"])

See here for more details.