def delete_older_than(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) deleted = [] backup_date_filter = int( datetime.utcnow().strftime("%s")) - interval_seconds for backup in Backups.search(filename, destination, older_than=backup_date_filter, 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 delete_older_than(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) deleted = [] backup_date_filter = int(datetime.utcnow().strftime("%s")) - interval_seconds for backup in Backups.search(filename, destination, older_than=backup_date_filter, 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 delete_older_than(filename, interval, destination=DEFAULT_DESTINATION, profile="default", **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 :type conf: dict :keyword conf: Override/set AWS configuration. :rtype: list :return: A list containing the deleted keys (S3) or archives (Glacier). """ conf = kwargs.get("conf") storage_backend = _get_store_backend(conf, destination, profile) interval_seconds = _interval_string_to_seconds(interval) deleted = [] backup_date_filter = int(datetime.utcnow().strftime("%s")) - interval_seconds for backup in Backups.search(filename, destination, older_than=backup_date_filter, profile=profile): real_key = backup.stored_filename log.info("Deleting {0}".format(real_key)) storage_backend.delete(real_key) backup.set_deleted() deleted.append(real_key) BakSyncer(conf).sync_auto() return deleted
def delete_older_than(filename, interval, destination=DEFAULT_DESTINATION, profile="default", **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 :type conf: dict :keyword conf: Override/set AWS configuration. :rtype: list :return: A list containing the deleted keys (S3) or archives (Glacier). """ conf = kwargs.get("conf") storage_backend = _get_store_backend(conf, destination, profile) interval_seconds = _interval_string_to_seconds(interval) deleted = [] backup_date_filter = int(datetime.utcnow().strftime("%s")) - interval_seconds query = "SELECT stored_filename FROM backups WHERE backend == '{0}' \ AND backup_date < {1:d} AND filename LIKE '{2}%' AND is_deleted == 0" for backup in dump_truck.execute(query.format(destination, backup_date_filter, filename)): real_key = backup.get("stored_filename") log.info("Deleting {0}".format(real_key)) storage_backend.delete(real_key) dump_truck_delete_backup(real_key) deleted.append(real_key) return deleted