Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- # Place this in a cron job for say every 2 minutes. To script this use
- # crontab -l | { cat; echo "0 0 0 0 0 some entry"; } | crontab -
- # You may also want to run ntpd on all clients to keep the time in sync.
- # Array of locations of local and remote locations. I recommend mounting remote folders in
- # Example (('/home/user/Documents', '/remotehostname/somefolder'),)
- sync_locations = (
- ("/home/david/local", "/home/david/server"),
- )
- # Check if host is up
- check_host = "localhost"
- # Only allow this program to run once!
- try:
- import socket
- s = socket.socket()
- host = socket.gethostname()
- port = 35636 #make sure this port is not used on this system
- s.bind((host, port))
- except:
- exit()
- if not os.path.exists(os.getenv("HOME") + '/.unison_backup'):
- os.mkdir(os.getenv("HOME") + '/.unison_backup')
- if os.path.exists(sync_locations[0][0]) and 0 == os.system('ping -c 1 ' + check_host):
- if not os.path.isfile(os.getenv("HOME") + "/.unison_backup/first_sync_complete"):
- os.system('notify-send "Unison Backup" "Starting Initial Sync. You will be notified when finished."')
- for sync_location in sync_locations:
- exit_code = os.system('rsync -r ' + sync_location[1] + "/ " + sync_location[0])
- if exit_code != 0:
- os.system('notify-send "Could not sync!"')
- exit()
- open(os.getenv("HOME") + '/.unison_backup/first_sync_complete', 'w').close()
- os.system('notify-send "Unison Backup" "Initial Sync Complete"')
- # Run Unison
- for sync_location in sync_locations:
- os.system('unison %s %s -batch -prefer newer -times=true' % (sync_location[0], sync_location[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement