python / 未分类 · 2013年10月29日

python包装rsync

#!/usr/bin/env python
#wraps up rsync to synchronize two directories
from subprocess import call
import sys
import time
source = "/tmp/sync_dir_A/" #Note the trailing slash
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)
#print cmd
if ret !=0:
print "resubmitting rsync"
time.sleep(30)
else:
print "rsync was succesful"
# subprocess.call("mail -s 'evanjobs done' evan886@gmail.com", shell=True)
sys.exit(0)
sync()