Created
March 12, 2009 22:01
-
-
Save jonmagic/78312 to your computer and use it in GitHub Desktop.
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/bin/python | |
import traceback | |
# tb = file('tb.txt', 'w') | |
# try: | |
import os, string, time, datetime, sys | |
def mount_disk(disk): | |
command = 'sudo mount %s /media/disk1' % (disk) | |
os.popen(command) | |
def unmount_disk(): | |
command = "sudo umount /media/disk1" | |
os.popen(command) | |
def create_backup(dt): | |
os.chdir('/media/disk1') | |
command = "sudo zip -r /Backups/backup_%s.zip *" % (dt) | |
os.popen(command) | |
def restore_backup(filename): | |
command = "sudo unzip -o %s -d /media/disk1/" % (filename) | |
os.popen(command) | |
def is_disk1_mounted(): | |
result = os.popen('sudo mount | awk -F" " \'/\/media\/disk1/ {print $3}\'') | |
if result.read() != "": | |
return True | |
else: | |
return False | |
def find_FAT16_partition(): | |
result = os.popen('sudo fdisk -l /dev/sd* | awk -F" " \'/FAT16/ {print $1}\'') | |
return result.read().replace("\n", "") | |
def create_list_of_backups(): | |
result = os.popen('ls /Backups/*.zip') | |
array = result.read().split("\n") | |
array.remove("") | |
return array | |
def menu1(): | |
os.system('clear') | |
print "Select a command below by typing the number and pressing Enter" | |
print "1. Backup this machine" | |
print "2. Restore this machine to earlier backup" | |
print "3. REBOOT" | |
key = raw_input('\n# ') | |
menu1_commands(key) | |
def menu1_commands(key): | |
if key == "1": | |
dt = datetime.datetime.now().strftime("%m-%d-%y_%H:%M:%S") | |
print "\nCreating backup /Backups/backup_%s.zip" % (dt) | |
create_backup(dt) | |
print "Backup Complete!" | |
time.sleep(5) | |
menu1() | |
elif key == "2": | |
print "\nLoading list of previous backups" | |
time.sleep(1) | |
menu2() | |
elif key == "3": | |
print "\nREBOOTING!" | |
else: | |
print "\nYou hit an invalid option" | |
time.sleep(3) | |
menu1() | |
def menu2(): | |
os.system('clear') | |
backups = create_list_of_backups() | |
n = 1 | |
keyed_backups = {} | |
print "Select the backup you would like to restore, press the number and then press Enter." | |
for backup in backups: | |
keyed_backups[str(n)] = backup | |
print "%s. %s" % (n, backup) | |
n = n + 1 | |
print "c. Press c and then Enter to return to the main menu" | |
key = raw_input('\n# ') | |
menu2_commands(key, keyed_backups) | |
def menu2_commands(key, keyed_backups): | |
if key == "c": | |
menu1() | |
else: | |
print "\nRestoring %s to /media/disk1" % (keyed_backups[key]) | |
restore_backup(keyed_backups[key]) | |
print "Restore Completed!" | |
time.sleep(5) | |
menu1() | |
if is_disk1_mounted(): | |
menu1() | |
else: | |
mount_disk(find_FAT16_partition()) | |
menu1() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment