def test_internals(self): with self.assertRaises(Exception): bakthat._interval_string_to_seconds("1z") self.assertEqual(bakthat._interval_string_to_seconds("2D1h"), 86400 * 2 + 3600) self.assertEqual(bakthat._interval_string_to_seconds("3M"), 3 * 30 * 86400)
def test_internals(self): with self.assertRaises(Exception) as ar: bakthat._match_filename("", "s3") with self.assertRaises(Exception) as ar: bakthat._interval_string_to_seconds("1z") self.assertEqual(bakthat._interval_string_to_seconds("2D1h"), 86400 * 2 + 3600) self.assertEqual(bakthat._interval_string_to_seconds("3M"), 3*30*86400)
def delete_older_filename(filename, interval, profile="default", config=CONFIG_FILE, destination=None, **kwargs): """Delete backups matching the given filename older than the given interval string. :type filename: str :param filename: File/directory name. :type interval: str :param interval: Interval string like 1M, 1W, 1M3W4h2s... (s => seconds, m => minutes, h => hours, D => days, W => weeks, M => months, Y => Years). :type destination: str :param destination: glacier|s3|swift :type conf: dict :keyword conf: Override/set AWS configuration. :rtype: list :return: A list containing the deleted keys (S3) or archives (Glacier). """ storage_backend, destination, conf = _get_store_backend(config, destination, profile) session_id = str(uuid.uuid4()) events.before_delete_older_than(session_id) interval_seconds = _interval_string_to_seconds(interval) backup_date_filter = int(datetime.utcnow().strftime("%s")) - interval_seconds deleted = [] for backup in Backups.search_older_than(filename, backup_date_filter, destination=destination, profile=profile, config=config): real_key = backup.stored_filename log.info("Deleting {0}".format(real_key)) storage_backend.delete(real_key) backup.set_deleted() deleted.append(backup) events.on_delete_older_than(session_id, deleted) return deleted
def test_internals(self): with self.assertRaises(Exception): bakthat._interval_string_to_seconds("1z") self.assertEqual(bakthat._interval_string_to_seconds("2D1h"), 86400 * 2 + 3600) self.assertEqual(bakthat._interval_string_to_seconds("3M"), 3*30*86400)