Created
November 20, 2017 15:59
-
-
Save TimSC/b7af0e82af18548cb6f2135b4346370b to your computer and use it in GitHub Desktop.
Invoke rsync using python/cron
This file contains hidden or 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/env python | |
import subprocess | |
import fcntl | |
import os | |
if __name__=="__main__": | |
lockFina = "docslock" | |
fullLockFina = os.path.join(os.path.dirname(os.path.realpath(__file__)), lockFina) | |
if not os.path.exists(fullLockFina): | |
fi = open(fullLockFina, "w") | |
else: | |
fi = open(fullLockFina, "r") | |
#Try to get exclusive lock, quit if this fails | |
#This stops multiple instances of rsync running at the same time | |
fcntl.flock(fi, fcntl.LOCK_EX | fcntl.LOCK_NB) | |
# https://stackoverflow.com/a/18482169/4288232 | |
subprocess.call(["rsync", "-avz", "-delete", "-e", "ssh", "/home/user/Documents/", "user@nas:/path/to/backup"]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment