From 43d2b487bac2bb48531ac52d68750221861c7c7b Mon Sep 17 00:00:00 2001 From: "David Adam (zanchey)" <zanchey@ucc.gu.uwa.edu.au> Date: Thu, 6 Sep 2012 10:56:02 +0800 Subject: [PATCH] properly test if destination exists and create it if not --- rdiff-manager.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/rdiff-manager.py b/rdiff-manager.py index 478183d..87356b1 100755 --- a/rdiff-manager.py +++ b/rdiff-manager.py @@ -28,13 +28,24 @@ class Host(object): return run_rdiff('--test-server', 'root@%s::/' % self.hostname) def test_directory(self): + # ensure destination is rdiff-backup target try: - os.makedirs(self.destination) - except OSError as e: - if os.access(self.destination, os.F_OK): - pass - else: - raise e + run_rdiff('--list-increments', self.destination) + except subprocess.CalledProcessError: + # check if base directory exists + try: + os.makedirs(self.destination) + except OSError as e: + if os.access(self.destination, os.X_OK): + pass + else: + raise e + # create baseline empty data directory + run_rdiff(*(self.run_backup_flags.split(' ') + [ '--exclude', + '**', 'root@%s::/' % (self.hostname), self.destination ] ) ) + else: + pass + def remove_old(self): # even with force, only increments are removed, never the most recent backup -- GitLab