python如何操作rsync
PHP中文网
PHP中文网 2017-04-17 17:29:19
0
2
468

rt
没找到相关模块

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
迷茫

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.

Peter_Zhu

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!