From 6f63f9fae8af223bc82b696e989fd1b9b7985161 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sun, 30 May 2010 23:34:23 +0200 Subject: ryrestore: improved error handling --- ryrestore.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'ryrestore.py') diff --git a/ryrestore.py b/ryrestore.py index 1404a38..9577a39 100755 --- a/ryrestore.py +++ b/ryrestore.py @@ -25,10 +25,7 @@ from rybackup import bak, bin, mount # # Managing backup snapshots def select(source): - try: - snapshots = listdir(source) - except OSError: - raise SystemExit("Error: unable to read backup source") + snapshots = listdir(source) # Present the selection to the user, with numbered IDs for index, directory in enumerate(snapshots): @@ -43,13 +40,16 @@ def select(source): def restore(source, destination): try: bsnap = select(source) - except (ValueError, IndexError): - raise SystemExit("Error: incorrect snapshot ID") - - # Mirroring options - rsyncopt = ( + except KeyboardInterrupt: + print "\nError: user initiated exit" + return + except Exception, error: + print "Error: incorrect snapshot ID or backup source\nDebug:", error + return + + rsyncopt = ( # Mirroring options "--archive", # use the archive mode, - "--verbose", # increase verbosity, + "--verbose", # increase verbosity ) # Restore from backup with rsync @@ -65,9 +65,10 @@ def main(): if getuid() != 0: raise SystemExit("Error: super user privileges required") try: - mount("mount") - restore(bak['dst'], argv[1]) - mount("umount") + if argv[1] != None: + mount("mount") + restore(bak['dst'], argv[1]) + mount("umount") except IndexError: raise SystemExit(usage) -- cgit v1.2.3