From 4a975b38f1fd1bf7004ad3922c382baa9b0d9f9e Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 27 Feb 2019 16:51:43 -0800 Subject: [PATCH] Implemented the actual deleting part --- backup-rotator | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backup-rotator b/backup-rotator index f315e09..0520adf 100644 --- a/backup-rotator +++ b/backup-rotator @@ -3,6 +3,7 @@ import datetime import os +import shutil import sys import yaml @@ -104,8 +105,14 @@ class BackupRotator: for purge_index in range(purge_count): item_to_purge = self.pick_item_to_purge(children) - self.log("Purging item:", item_to_purge) children.remove(item_to_purge) + self.log("Purging item:", item_to_purge) + if os.path.isfile(item_to_purge): + os.remove(item_to_purge) + elif os.path.isdir(item_to_purge): + shutil.rmtree(item_to_purge) + else: + raise Exception("Don't know how to remove this item: " + str(item_to_purge)) def gather_rotation_candidates(self, path):