将系统调用包装到rsync的python模块
sysrsync的Python项目详细描述
系统同步
将系统调用包装到rsync的python模块
要求
- rsync
- Python3.6+
开发:
- pipenv(确保pipenv和pip都升级到最新版本)
用法
- 基本文件同步
importsysrsyncsysrsync.run(source='/home/user/foo.txt',destination='/home/server/bar')# runs 'rsync /home/users/foo.txt /home/server/files'
- 带有选项的ssh
importsysrsyncsysrsync.run(source='/home/user/files',destination='/home/server/files',destination_ssh='myserver',options=['-a'])# runs 'rsync -a /home/users/files/ myserver:/home/server/files'
- 除外条款
importsysrsyncsysrsync.run(source='/home/user/files',destination='/home/server/files',destination_ssh='myserver',options=['-a'],exclusions=['file_to_exclude','unwanted_file'])# runs 'rsync -a /home/users/files/ myserver:/home/server/files --exclude file_to_exclude --exclude unwanted_file'
API
sysrsync.run
argument | type | default | description |
---|---|---|---|
cwd | str | ^{ | working directory in which subprocess will run the rsync command |
strict | bool | ^{ | raises ^{ |
verbose | bool | ^{ | verbose mode: currently prints rsync command before executing |
**kwargs | dict | Not Applicable | arguments that will be forwarded to call to ^{ |
返回:subprocess.CompletedProcess
在strict = True
和rsync返回代码不同于0(Success)时引发:RsyncError
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 | Iterable[str] | [] | List of excluded patterns as in rsync's ^{ |
sync_source_contents | bool | True | Abstracts the elusive trailing slash behaviour that ^{ |
options | Iterable[str] | [] | List of options to be used right after rsync call, e.g. ^{ |
返回:List[str]
->;要直接在subprocess.run
中使用的命令的编译列表
在同时设置source_ssh
和target_ssh
时引发:RemotesError
。通常linux rsync发行版不允许源和目标同时是远程的。