rsyncer is a simple rsync wrapper for python.
You need to have an rsync installation on your system and added to your system's path.
- download this repository
- from within this repo run
make install
- test installation by importing
rsyncer
in a python shell
You can choose between the simple One-Function-Call and the more powerful Syncer utility to run rsync commands using rsyncer.
This is the simplest usage of rsyncer. You can just call the rsync
function with the necessary arguments to run a
rsync command. This function will return a boolean indicating if the process finished successfully or not:
from rsyncer.rsync import rsync
suc = rsync(...)
if suc:
print("rsync run successfully.")
else:
print("There was an error running rsync.")
With this utility, you get a larger set of functionalities like
- creating a rsync command
- running a rsync command
- get the current progress of a running rsync process
- ...
Mark:
rsyncer.rsync.Syncer
creates a temporary files in/tmp
where rsync's output is written to. Therefore, aSyncer
should be closed when you are done working with it (The rsync subprocess will not be killed).
You can either create a Syncer
object and use its close()
(or exit()
, which will kill the rsync process) method in
the end, or you can use a Syncer
within a with
statement:
from rsyncer import rsync
s = rsync.Syncer(...)
s.run()
s.get_command()
s.progress()
# and/or other operations
s.close() # or s.exit() if you want to kill the rsync process as well
from rsyncer import rsync
with rsync.Syncer(...) as s:
s.run()
s.get_command()
s.progress()
# and/or other operations
As far as possible, we provide a One-Function-Call and a Syncer implementation for each example.
$ rsync /path/to/file /path/to/destination
from rsyncer import rsync
rsync.rsync(source="/path/to/file", dest="/path/to/destination")
from rsyncer import rsync
with rsync.Syncer(source="/path/to/file", dest="/path/to/destination") as s:
s.run()
$ rsync /path/to/dir /path/to/destination
from rsyncer import rsync
rsync.rsync(source="/path/to/dir", dest="/path/to/destination")
from rsyncer import rsync
with rsync.Syncer(source="/path/to/dir", dest="/path/to/destination") as s:
s.run()
$ rsync -a user@server.org:/path/to/dir /path/to/destination
from rsyncer import rsync
rsync.rsync(source="/path/to/dir", dest="/path/to/destination", source_ssh="user@server.org")
from rsyncer import rsync
with rsync.Syncer(source="/path/to/dir", dest="/path/to/destination", source_ssh="user@server.org") as s:
s.run()
$ rsync /path/to/dir /path/to/destination --exclude /path/to/dir/tmp.txt
from rsyncer import rsync
rsync.rsync(source="/path/to/dir", dest="/path/to/destination", excludes=["/path/to/dir/tmp.txt"])
from rsyncer import rsync
with rsync.Syncer(source="/path/to/dir", dest="/path/to/destination", excludes=["/path/to/dir/tmp.txt"]) as s:
s.run()