search

Home  >  Q&A  >  body text

python如何操作rsync

rt
没找到相关模块

PHP中文网PHP中文网2827 days ago520

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-17 17:31:19

    There are several optional solutions, which can be chosen according to the actual situation (running platform, application requirements).

    Option 1: Use python to encapsulate the call to the local rsync program
    If the requirements are relatively simple and there is a local rsync program available on the running platform, you can use the subprocess module to encapsulate the call command to rsync (you can also use the os module to encapsulate, principle are the same as above), for example:

    cmd = "rsync -avrz /opt/data/filename root@ip:/opt/data/file"
    subprocess.call(cmd, shell=True)
    

    The advantage of this solution is that it is simple to implement and not prone to bugs. The disadvantage is that if you run on a Windows platform, it is more troublesome and you need to install a local rsync program, such as through cygwin.

    Option 2, python implementation of rsync protocol:
    Vivian De Smedt provides a python implementation for rsync on Bitbucket, which is very small and only 15KB.
    https://bitbucket.org/vds2212/rsync.py

    The advantage of this approach is that it is platform-independent and can be used on any platform running python. However, since this is a personal implementation, it may have bugs, be incompatible with standard rsync, and require time to learn how to use the script, etc.

    If the purpose is just to call rsync in a python script to complete an automated daily maintenance task on the Linux platform, then the first option is recommended.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:31:19

    Haha, there is no search for related modules....
    You can find several by just searching for pypi.
    https://pypi.python.org/pypi?%3Aaction=search&term=rsync&submit=search

    reply
    0
  • Cancelreply