Skip to content

Commit 4f10e32

Browse files
corey-hammertontimvaillancourt
authored andcommitted
Rotate: Wrapping the rotate removal under a try-catch block. (#278)
The original code would raise an OperationError is the backup path doesn't exist. This is not the only reason a rmtree would fail, insufficient permissions, invalid SELinux contexts, etc. This commit wraps the rmtree functionality in a try-catch block to catch and log any exceptions that may happen.
1 parent ee84740 commit 4f10e32

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mongodb_consistent_backup/Rotate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def backups_by_unixts(self):
4343
def remove(self, ts):
4444
if ts in self.backups:
4545
backup = self.backups[ts]
46-
if os.path.isdir(backup["path"]):
46+
try:
4747
logging.debug("Removing backup path: %s" % backup["path"])
4848
rmtree(backup["path"])
49-
else:
50-
raise OperationError("Backup path %s does not exist!" % backup["path"])
49+
except Exception, e:
50+
raise OperationError("Unable to remove backup path %s. %s" % backup["path"], e)
5151
if self.previous == backup:
5252
self.previous = None
5353
del self.backups[ts]

0 commit comments

Comments
 (0)