rsync to synchronize

2020-01-13 15:53:43 浏览数 (1)

python code  rsync 

代码语言:javascript复制
#!/usr/bin/env pyt hon 
#wraps up rsync to synchronize two directories 
 
from subprocess import call 
import sys 
import time 
 
"""this motivated rsync tries to synchronize forever""" 
 
source = "/tmp/sync_dir_A" 
target = "/tmp/sync_dir_B" 
rsync  = "rsync" 
arguments = "-av" 
cmd = "%s %s %s %s" % (rsync,arguments,source,target) 
 
def sync(): 
    while True: 
        ret = call(cmd,shell=True) 
        if ret !=0: 
            print "resubmitting rsync" 
            time.sleep(5) 
        else: 
            print "rsync was successful" 
            cmd_mail="echo 'jobs done'|mail -s 'jobs done' itnihao@qq.com" 
            call(cmd_mail,shell=True) 
            sys.exit(0) 
sync() 

0 人点赞