Created
August 11, 2014 06:38
-
-
Save anonymous/2bd1676ca95281a42d37 to your computer and use it in GitHub Desktop.
realtime rsync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#-*-coding:utf8-*- | |
import pyinotify,os,subprocess | |
sourcePath = '/home/yjiang/foo/' | |
targetPath = 'yjiang@test:/home/yjiang/sync_test/' | |
wm = pyinotify.WatchManager() | |
class rsync(): | |
def __init__(self, type, path): | |
cmd = 'rsync -avz --delete %s %s' %(sourcePath, targetPath) | |
subprocess.call(cmd, shell=True) | |
print "%s: %s" % (type, path) | |
class EventHandler(pyinotify.ProcessEvent): | |
def process_IN_CREATE(self, event): | |
rsync('create', event.pathname) | |
def process_IN_DELETE(self, event): | |
rsync('delete', event.pathname) | |
def process_IN_MODIFY(self, event): | |
rsync('modify', event.pathname) | |
notifier = pyinotify.Notifier(wm, EventHandler()) | |
wm.add_watch(sourcePath, pyinotify.ALL_EVENTS) | |
notifier.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment