sysrsync
Simple and safe native rsync wrapper for Python 3
Requirements
- rsync
- python 3.6+
development:
- poetry (be sure to have both poetry and pip upgraded to the latest version)
Installation
pip install sysrsync
Basic rules
- Syncs source contents by default, so it adds a trailing slash to the end of source, unless
sync_source_contents=Falseis specified - Removes trailing slash from destination
- Extra arguments are put right after
rsync - Breaks if
source_sshanddestination_sshare both set
Usage
- Basic file sync
import sysrsync
sysrsync.run(source='/home/user/foo.txt',
destination='/home/server/bar')
# runs 'rsync /home/users/foo.txt /home/server/files'
- sync whole folder
import sysrsync
sysrsync.run(source='/home/user/files',
destination='/home/server/',
sync_source_contents=False)
# runs 'rsync /home/user/files /home/server'
- sync folder contents
import sysrsync
sysrsync.run(source='/home/user/files',
destination='/home/server/',
sync_source_contents=True)
# runs 'rsync /home/user/files/ /home/server'
- ssh with options
import sysrsync
sysrsync.run(source='/home/user/files',
destination='/home/server/files',
destination_ssh='myserver',
options=['-a'])
# runs 'rsync -a /home/users/files/ myserver:/home/server/files'
- exclusions
import sysrsync
sysrsync.run(source='/home/user/files',
destination='/home/server/files',
destination_ssh='myserver',
options=['-a'],
exclusions=['file_to_exclude', 'unwanted_file'])
# runs 'rsync -a /home/user/files/ myserver:/home/server/files --exclude file_to_exclude --exclude unwanted_file'
- Private key
import sysrsync
sysrsync.run(source='/home/user/files',
destination='/home/server/files',
destination_ssh='myserver',
private_key="totally_secure_key")
# runs 'rsync --rsh='ssh -i totally_secure_key' /home/user/files/ myserver:/home/server/files'
API
sysrsync.run
| argument | type | default | description |
|---|---|---|---|
| cwd | str | os.getcwd() |
working directory in which subprocess will run the rsync command |
| strict | bool | True |
raises RsyncError when rsync return code is different than 0 |
| verbose | bool | False |
verbose mode: currently prints rsync command before executing |
| **kwargs | dict | Not Applicable | arguments that will be forwarded to call to sysrsync.get_rsync_command |
returns: subprocess.CompletedProcess
raises:
RsyncErrorwhenstrict = Trueand rsync return code is different than 0 (Success)
sysrsync.get_rsync_command
| argument | type | default | description |
|---|---|---|---|
| source | str | - | Source folder or file |
| destination | str | - | Destination folder |
| source_ssh | Optional[str] | None | Remote ssh client where source is located |
| destination_ssh | Optional[str] | None | Remote ssh client where destination is located |
| exclusions | Optional[Iterable[str]] | None | List of excluded patterns as in rsync's --exclude |
| sync_source_contents | bool | True | Abstracts the elusive trailing slash behaviour that source normally has when using rsync directly, i.e. when a trailing slash is present in source, the folder's content is synchronized with destination. When no trailing slash is present, the folder itself is synchronized with destination. |
| options | Optional[Iterable[str]] | None | List of options to be used right after rsync call, e.g. ['-a', '-v'] translates to rsync -a -v |
| private_key | Optional[str] | None | Configures an explicit key to be used with rsync --rsh command |
| rsh_port | Optional[int] | None | Specify port to be used for --rsh command |
| strict_host_key_checking | Optional[bool] | None | set StrictHostKeyChecking property for rsh #cf. https://superuser.com/questions/125324/how-can-i-avoid-sshs-host-verification-for-known-hosts |
returns: List[str] -> the compiled list of commands to be used directly in subprocess.run
raises:
RemotesErrorwhen bothsource_sshanddestination_sshare set. Normally linux rsync distribution disallows source and destination to be both remotes.PrivateKeyErrorwhenprivate_keydoesn't exist
Contributing
- Fork project
- Install dependencies with
poetry install - Make changes
- Lint with
poetry run pylint ./sysrsync - Test with
poetry run python -m unittest - Run end-to-end tests with
bash end-to-end-tests/run-tests.sh - Submit changes with a pull request
Contributors ✨
Thanks goes to these wonderful people (emoji key):
plazmakeks 💻 |
Steve Henderson 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
Metadata
Release files for sysrsync 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sysrsync-1.1.1.tar.gz | 6.9 kB | Without provenance | Details for sysrsync-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sysrsync-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for sysrsync-1.1.1-py3-none-any.whl |
Total release size: 14.4 kB
Release files / sysrsync-1.1.1.tar.gz
| Download URL | sysrsync-1.1.1.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
435f9eb620e68ffb18ca5cbad32b113396a432361c7722038eab65c97dd83bd5
|
|
BLAKE2b-256 checksum How to use checksums |
24a0eaf4f0691639d603ba3da73c4ebbd3da22dfae09565ab7ba38bc28d17de2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.10.10 Linux/6.1.24-1-lts
|
Release files / sysrsync-1.1.1-py3-none-any.whl
| Download URL | sysrsync-1.1.1-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c8877f162dce9c480804445fca56cd19bf41b998d2172651468ccebfdc60850
|
|
BLAKE2b-256 checksum How to use checksums |
ce825939e68632beebdb6f61a52246c0243e8490d9f75e0f1a214dda0113d5f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.10.10 Linux/6.1.24-1-lts
|
Security for sysrsync 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.