Created
November 21, 2015 17:42
-
-
Save jasonraimondi/bf72c5b624bfadd008a0 to your computer and use it in GitHub Desktop.
Full System Backup
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/local/bin/python | |
import os | |
import sys | |
from datetime import datetime | |
NAMESPACE = 'TheServerBackup' | |
START = datetime.now() | |
TODAY = datetime.strftime(START, '%Y-%m-%d') | |
print sys.argv | |
LOCKFILE = '/mnt/Extras/Backups/' + NAMESPACE + '/' + TODAY + '.tar.gz' | |
TEMPFILE = '/tmp/' + NAMESPACE + TODAY | |
def query_yes_no(question, default="yes"): | |
valid = { | |
"yes": True, | |
"y" : True, | |
"ye" : True, | |
"no" : False, | |
"n" : False | |
} | |
if default is None: | |
prompt = " [y/n] " | |
elif default == "yes": | |
prompt = " [Y/n] " | |
elif default == "no": | |
prompt = " [y/N] " | |
else: | |
raise ValueError("invalid default answer: '%s'" % default) | |
while True: | |
sys.stdout.write(question + prompt) | |
choice = raw_input().lower() | |
if default is not None and choice == '': | |
return valid[default] | |
elif choice in valid: | |
return valid[choice] | |
else: | |
sys.stdout.write("Please respond with 'yes' or 'no' " | |
"(or 'y' or 'n').\n") | |
def main(): | |
if os.path.exists(LOCKFILE): | |
print "There is already a backup file for today at:" | |
print LOCKFILE | |
choice = query_yes_no("Would you like to remove and replace the existing backup?", "no") | |
if choice: | |
os.system('rm -rf ' + LOCKFILE) | |
else: | |
print "\n" | |
print "Not doing anything, keeping your old backup." | |
os.system('rsync --partial --archive --acls --update --partial --progress --delete-after ' + | |
'/* ' + TEMPFILE + | |
' --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/opt/snapraid/*,/var/lib/plexmediaserver/*,/lost+found,/pool/*}') | |
os.system('tar -cvzf ' + LOCKFILE + ' ' + TEMPFILE) | |
os.system('rm -rf ' + TEMPFILE) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment