def checkMaxImages(backupHome, maxImages): """ When the number of backup images are greater than the max provided in settings, mark the extra images to be deleted. """ backups = fn.getBackups(backupHome) if len(backups.keys()) > maxImages: toRemove = list(backups.keys())[:len(backups.keys()) - maxImages] for id in toRemove: fn.markBackupForDeletion(backupHome, backups[id])
def organize(backupHome): """ Reduce the backups to a frequency of daily for those that are older than one day, and to weekly for those that are older than 31 days. """ catagorized = _catagorize(fn.getBackups(backupHome).values()) for backup in _getExtraDailyBackups(catagorized["daily"]): fn.markBackupForDeletion(backupHome, backup) for backup in _getExtraWeeklyBackups(catagorized["weekly"]): fn.markBackupForDeletion(backupHome, backup)
def checkForKeepDays(backupHome, keepDays): """ When the number of days a backup exists is greater than keepDays, those older backups are deleted. Do not delete any backups if keepDays is zero. """ def isOld(backup): dt = fn.toDateTime(backup) expire = datetime.now() - timedelta(days=keepDays) return dt <= expire backups = fn.getBackups(backupHome).values() toRemove = filter(isOld, backups) for backup in toRemove: fn.markBackupForDeletion(backupHome, backup)
def test_markBackupForDeletion(self): backup = "2012-01-28-120628" backupPath = join(self._backupHome, backup) os.makedirs(backupPath) fn.markBackupForDeletion(self._backupHome, backup) self.assertTrue(os.path.exists(backupPath + ".delete"))