From e56611c3e966f758889d7b49f9818a43ae90c5ec Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 14 May 2012 11:20:08 +0200 Subject: [PATCH] ask before making backup --- shbackup | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/shbackup b/shbackup index 351aef9..17bd331 100755 --- a/shbackup +++ b/shbackup @@ -305,23 +305,29 @@ class BackupManager: if mode != "full": print("** Warning: full backup recommended!") - # Create new target directory - basedir = self.conf.directory - dirname = Backup.getDirName(now, epoch, mode) - tmpdirname = dirname + ("-%x" % (random.random()*2e16) ) - targetdir = os.path.join(basedir, tmpdirname) - os.mkdir( targetdir ) # If we have a full backup, we backup everything since = None - - # Get latest full backup time if mode == "diff": since = sorted(oldfullbackups, key=lambda b: b.date)[-1].date - # Get latest backup time elif mode == "incr": since = sorted(oldbackups, key=lambda b: b.date)[-1].date + if since != None: + print("Making backup relative to ", since.ctime()) + + yesno = self.ask_user_yesno("Proceed? [Y, n] ") + if yesno == "n": + return + + # Create new target directory + basedir = self.conf.directory + dirname = Backup.getDirName(now, epoch, mode) + tmpdirname = dirname + ("-%x" % (random.random()*2e16) ) + targetdir = os.path.join(basedir, tmpdirname) + os.mkdir( targetdir ) + + # Backup all file sets for s in self.conf.sets: self.backupFileSet(s, targetdir, since) @@ -375,7 +381,7 @@ class BackupManager: return basedir = self.conf.directory - yesno = self.ask_user_yesno("Remove entries marked by '*'?") + yesno = self.ask_user_yesno("Remove entries marked by '*'? [y, N] ") if yesno == "y": for d in removeDirs: shutil.rmtree(os.path.join(basedir, d)) @@ -385,7 +391,7 @@ class BackupManager: print(question + " y") return "y" else: - return input(question + " [y, N] ") + return input(question) def printUsage(): -- 2.39.5