将系统调用包装到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

argumenttypedefaultdescription
cwdstr^{}working directory in which subprocess will run the rsync command
strictbool^{}raises ^{} when rsync return code is different than 0
verbosebool^{}verbose mode: currently prints rsync command before executing
**kwargsdictNot Applicablearguments that will be forwarded to call to ^{}

返回subprocess.CompletedProcess

strict = True和rsync返回代码不同于0(Success)时引发RsyncError

sysrsync.get_rsync_command

argumenttypedefaultdescription
sourcestr-Source folder or file
destinationstr-Destination folder
source_sshOptional[str]NoneRemote ssh client where source is located
destination_sshOptional[str]NoneRemote ssh client where destination is located
exclusionsIterable[str][]List of excluded patterns as in rsync's ^{}
sync_source_contentsboolTrueAbstracts the elusive trailing slash behaviour that ^{} normally has when using rsync directly, i.e. when a trailing slash is present in ^{}, the folder's content is synchronized with destination. When no trailing slash is present, the folder itself is synchronized with destination.
optionsIterable[str][]List of options to be used right after rsync call, e.g. ^{} translates to ^{}

返回List[str]->;要直接在subprocess.run中使用的命令的编译列表

在同时设置source_sshtarget_ssh时引发RemotesError。通常linux rsync发行版不允许源和目标同时是远程的。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java接口中的每个方法都是抽象的,但在抽象类中,我们也只能使用抽象方法   初始化Java中声明的、未初始化的变量会发生什么情况?   java BouncyCastle openPGP将字节[]数组加密为csv文件   在Java中将类A(和所有子类)映射到类B的实例的字典   RSA公钥编码,在Java和Android中,代码相同,结果不同   java在安卓中实现数字检测语音识别   java取消选择复选框   java如何在其他配置中重用Maven配置XML片段   java有没有一种有效的方法来检查HashMap是否包含映射到相同值的键?   spring处理程序调度失败;嵌套的例外是java。lang.NoClassDefFoundError:org/apache/http/client/HttpClient   带有ehcache的java多层缓存   java如何访问chromium(或任何其他浏览器)cookie   java通过将两个集合与spring data mongodb data中的条件合并来获取计数   安卓中R.java的语法错误