V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wildcat007
V2EX  ›  Python

帮忙推荐一个 windows 好用的 Python rsync 模块~谢谢

  •  
  •   wildcat007 · 2017-01-20 14:30:33 +08:00 · 4336 次点击
    这是一个创建于 2652 天前的主题,其中的信息可能已经有所发展或是发生改变。
    windows 上用 pycharm 编程,最后还是要放到 centos 去运行~
    15 条回复    2017-01-22 10:52:09 +08:00
    Sentur
        1
    Sentur  
       2017-01-20 16:29:17 +08:00
    你意思是把代码都 push 到 centos 里去吗...
    我都是 lrzsz....
    wildcat007
        2
    wildcat007  
    OP
       2017-01-20 16:36:57 +08:00
    @Sentur 我这边是服务端,主要是对其他多个 rsync 下的目录文件进行监控,主机是 windows ,服务端是 centos 。

    在 windows 上面编码脚本,没发现好用的 rsync 模块,后来用了个 windows 下的 rsync.exe ,

    还是用的 os.popen()方式解决的问题,部分代码如下

    RSYNC = 'E:/xxxx/cwRsync_5.5.0_x86_Free/bin/rsync.exe '
    host = '10.3.5.70'

    dd = os.popen(RSYNC+host+"::"+"logs")
    Sentur
        3
    Sentur  
       2017-01-20 16:50:19 +08:00
    @wildcat007 我很少在 win 上折腾。。
    https://pypi.python.org/pypi/rsync.py
    你可以看看这个
    ilyh
        4
    ilyh  
       2017-01-20 16:54:57 +08:00
    Pycharm 的 Deployment 不是支持 ssh,ftp 同步的吗?
    wildcat007
        5
    wildcat007  
    OP
       2017-01-20 16:58:43 +08:00
    @Sentur 这个我看了的,他是 python 环境下可以直接利用这个脚本进行 rsync 的交互,这边自己调用系统命令基本完成好了。

    @ilyh 我这里不是同步数据,主要是对 rsync 的数据进行监控,查看增量,然后通过一定的逻辑,去动态拉取这个数据。
    wildcat007
        6
    wildcat007  
    OP
       2017-01-20 18:02:47 +08:00
    渣渣代码分享下
    [code]#!/usr/bin/env python
    # coding=utf-8
    # author=Tonybreak

    import os
    import platform
    import time

    WIN_RSYNC = 'E:/xxxx/cwRsync_5.5.0_x86_Free/bin/rsync.exe'
    LINUX_RSYNC = '/usr/bin/rsync'
    HOST = '10.3.5.70'
    MOD_NAME = 'logs'


    def i_system():
    return platform.system()

    def choose_rsync():

    if i_system() == "Windows":
    rsync = WIN_RSYNC
    elif i_system() == "Linux":
    rsync = LINUX_RSYNC
    else:
    rsync = "Maybe something is wrong."

    return rsync

    def rsync_cmd():

    target = []
    rsync = choose_rsync()
    cmds = '%s %s::%s' %(rsync,HOST,MOD_NAME)
    dd = os.popen(cmds)

    for d in dd:
    target.append(d.strip().split(' '))

    for i in target:
    d4 = int(i[-4].replace(',', ''))
    t = str(i[-3] + ' ' + i[-2])
    t1 = time.strptime(t, '%Y/%m/%d %H:%M:%S')
    t3 = int(time.mktime(t1))
    print i[-1], t3, d4


    def main():
    rsync_cmd()


    if __name__ == '__main__':
    main()
    [/code]
    jarlyyn
        7
    jarlyyn  
       2017-01-20 18:21:00 +08:00
    不在 linux 下写,也请开个 linux 虚拟机吧……

    有时候不同 Linux 发行版的差异都会坑死人的。
    wildcat007
        8
    wildcat007  
    OP
       2017-01-20 21:32:19 +08:00
    @jarlyyn 我有 linux 的服务器,写完的代码直接同步过去运行测试了的。在 linux 的 vim 下写代码,真心难受。还是算了吧
    Technetiumer
        9
    Technetiumer  
       2017-01-20 21:40:37 +08:00
    不习惯 Vim ,试试 Emacs 吧
    jarlyyn
        10
    jarlyyn  
       2017-01-21 00:12:11 +08:00
    @wildcat007

    首先,linux 下压根不用 vim 写程序。我用 visualcode,挺好。

    其次,为什么跑 linux 虚拟机一定要在 linux 里编辑,你在 mount 个本地文件夹,在 windows 下编辑不就好了
    wildcat007
        11
    wildcat007  
    OP
       2017-01-21 00:35:13 +08:00
    @Technetiumer
    @jarlyyn

    好的,我来试试~主要是 windows 上面办公(手动 doge 脸)
    Akkuman
        12
    Akkuman  
       2017-01-21 04:18:31 +08:00 via Android
    不如用 btsync
    LigeLaige
        13
    LigeLaige  
       2017-01-21 11:38:08 +08:00
    1. paramiko
    2. sshpass -p passwd ssh|scp
    xuboying
        14
    xuboying  
       2017-01-21 11:51:59 +08:00 via iPhone
    因为内存很大,我开了 linux 虚拟机开 pycharm.再 rsync
    kaneg
        15
    kaneg  
       2017-01-22 10:52:09 +08:00
    FileZilla + sftp
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   994 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 20:02 · PVG 04:02 · LAX 13:02 · JFK 16:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.