Skip to content

Instantly share code, notes, and snippets.

Created August 11, 2014 06:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2bd1676ca95281a42d37 to your computer and use it in GitHub Desktop.
Save anonymous/2bd1676ca95281a42d37 to your computer and use it in GitHub Desktop.
realtime rsync
#!/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