Remote Backup Doublechecker
My Remote Backup Script is working nicely. After the backup, it writes some status to a file, "rsync_completed.txt."
But I noticed a few days ago that one of my backups didn't run. That's probably because the computer wasn't on at the designated time, or possibly because nobody was logged in, or that the system was too busy to run that particular task.
In any case, I wrote a Remote Backup Occurred Doublechecker. It runs every time I log in. Because I'm crazy. I thought about making it a DOS batch script, but went with Python because it'd be faster for me that way.
And just to reveal my craziness, here it is (mostly):
But I noticed a few days ago that one of my backups didn't run. That's probably because the computer wasn't on at the designated time, or possibly because nobody was logged in, or that the system was too busy to run that particular task.
In any case, I wrote a Remote Backup Occurred Doublechecker. It runs every time I log in. Because I'm crazy. I thought about making it a DOS batch script, but went with Python because it'd be faster for me that way.
And just to reveal my craziness, here it is (mostly):
try: rsync_file = os.path.join(my_root, "rsync_completed.txt") scriptname = sys.argv[0] if os.sep in scriptname: scriptname = scriptname.rsplit(os.sep, 1)[1] ask_user = False if not os.path.exists(rsync_file): import win32con ask_user = True msg = "Could not verify backup with file %s. Backup now?" % rsync_file flags = win32con.MB_ICONWARNING | win32con.MB_YESNO else: mtime = os.path.getmtime(rsync_file) dur = datetime.timedelta(seconds=time.time() - mtime) if dur.days > 2: import win32con ask_user = True msg = "It's been %s days since the last backup. Backup now?" % dur flags = win32con.MB_ICONQUESTION | win32con.MB_YESNO if ask_user: import win32ui response = win32ui.MessageBox(msg, scriptname, flags) if response == 6: import subprocess cmd = os.path.join(my_root, "backup_to_dreamhost.bat") subprocess.Popen(cmd) except Exception, e: f = file(os.path.join(my_root, "Desktop", "%s Fail.txt") % scriptname, 'w') f.write("An exception occurred: %s %s\n" % (str(e.__class__), str(e))) traceback.print_exc(file = f) f.close()
Comments