barman.retention_policies module#

This module defines backup retention policies. A backup retention policy in Barman is a user-defined policy for determining how long backups and archived logs (WAL segments) need to be retained for media recovery. You can define a retention policy in terms of backup redundancy or a recovery window. Barman retains the periodical backups required to satisfy the current retention policy, and any archived WAL files required for complete recovery of those backups.

class barman.retention_policies.RecoveryWindowRetentionPolicy(context, value, unit, server)View on GitHub#

Bases: RetentionPolicy

Retention policy based on recovery window. The DBA specifies a period of time and Barman ensures retention of backups and archived WAL files required for point-in-time recovery to any time during the recovery window. The interval always ends with the current time and extends back in time for the number of days specified by the user. For example, if the retention policy is set for a recovery window of seven days, and the current time is 9:30 AM on Friday, Barman retains the backups required to allow point-in-time recovery back to 9:30 AM on the previous Friday.

__init__(context, value, unit, server)View on GitHub#

Constructor of the retention policy base class

_abc_impl = <_abc._abc_data object>#
_backup_report(source)View on GitHub#

Report obsolete/valid backups according to the retention policy

_kw = {'d': 'DAYS', 'm': 'MONTHS', 'w': 'WEEKS'}#
_point_of_recoverability()View on GitHub#

Based on the current time and the window, calculate the point of recoverability, which will be then used to define the first backup or the first WAL

_re = re.compile("\n        ^\\s*\n        recovery\\s+window\\s+of\\s+   # recovery window of\n        (\\d+)\\s+(day|month|week)s?  # N (day|month|week) with optional 's'\n        \\s*$\n        ", re.IGNORECASE|re.VERBOSE)#
_wal_report()View on GitHub#

Report obsolete/valid WALs according to the retention policy

classmethod create(server, context, optval)View on GitHub#

If given option and value from the configuration file match, creates the retention policy object for the given server

debug()View on GitHub#

Debug information

class barman.retention_policies.RedundancyRetentionPolicy(context, value, server)View on GitHub#

Bases: RetentionPolicy

Retention policy based on redundancy, the setting that determines many periodical backups to keep. A redundancy-based retention policy is contrasted with retention policy that uses a recovery window.

__init__(context, value, server)View on GitHub#

Constructor of the retention policy base class

_abc_impl = <_abc._abc_data object>#
_backup_report(source)View on GitHub#

Report obsolete/valid backups according to the retention policy

_re = re.compile('^\\s*redundancy\\s+(\\d+)\\s*$', re.IGNORECASE)#
_wal_report()View on GitHub#

Report obsolete/valid WALs according to the retention policy

classmethod create(server, context, optval)View on GitHub#

If given option and value from the configuration file match, creates the retention policy object for the given server

debug()View on GitHub#

Debug information

class barman.retention_policies.RetentionPolicy(mode, unit, value, context, server)View on GitHub#

Bases: object

Abstract base class for retention policies

__init__(mode, unit, value, context, server)View on GitHub#

Constructor of the retention policy base class

_abc_impl = <_abc._abc_data object>#
abstract _backup_report(source)View on GitHub#

Report obsolete/valid backups according to the retention policy

_propagate_retention_status_to_children(backup_info, report, ret_status)View on GitHub#

Propagate retention status to all backups in the tree.

Note

This has a side-effect. It modifies or add data to report dict.

Parameters:
  • backup_info (barman.infofile.BackupInfo) – The object we want to propagate the RETENTION STATUS from.

  • report (dict[str, str]) – The report data structure to be modified. Each key is the ID of a backup, and its value is the retention status of that backup.

  • ret_status (str) – The status of the backup according to retention policies

abstract _wal_report()View on GitHub#

Report obsolete/valid WALs according to the retention policy

backup_status(backup_id)View on GitHub#

Report the status of a backup according to the retention policy

classmethod create(server, option, value)View on GitHub#

If given option and value from the configuration file match, creates the retention policy object for the given server

abstract debug()View on GitHub#

Debug information

first_backup()View on GitHub#

Returns the first valid backup according to retention policies

first_wal()View on GitHub#

Returns the first valid WAL according to retention policies

report(source=None, context=None)View on GitHub#

Report obsolete/valid objects according to the retention policy

to_json()View on GitHub#

Output representation of the obj for JSON serialization

class barman.retention_policies.RetentionPolicyFactoryView on GitHub#

Bases: object

Factory for retention policy objects

classmethod create(option, value, server=None, server_name=None, catalog=None, minimum_redundancy=0)View on GitHub#

Based on the given option and value from the configuration file, creates the appropriate retention policy object for the given server

Either server or server_name and backup_info_list must be provided. If server (a barman.Server) is provided then the returned RetentionPolicy will update as the state of the barman.Server changes. If server_name and backup_info_list are provided then the RetentionPolicy will be a snapshot based on the backup_info_list passed at construction time.

policy_classes = [<class 'barman.retention_policies.RedundancyRetentionPolicy'>, <class 'barman.retention_policies.RecoveryWindowRetentionPolicy'>, <class 'barman.retention_policies.SimpleWALRetentionPolicy'>]#
class barman.retention_policies.ServerMetadata(server_name, backup_info_list, keep_manager, minimum_redundancy)View on GitHub#

Bases: object

Static retention metadata for a barman-managed server

This will return the same values regardless of any changes in the state of the barman-managed server and associated backups.

__init__(server_name, backup_info_list, keep_manager, minimum_redundancy)View on GitHub#
property available_backupsView on GitHub#
get_keep_target(backup_id)View on GitHub#
class barman.retention_policies.ServerMetadataLive(server, keep_manager)View on GitHub#

Bases: ServerMetadata

Live retention metadata for a barman-managed server

This will always return the current values for the barman.Server passed in at construction time.

__init__(server, keep_manager)View on GitHub#
property available_backupsView on GitHub#
get_keep_target(backup_id)View on GitHub#
property minimum_redundancyView on GitHub#
property nameView on GitHub#
property retention_policyView on GitHub#
class barman.retention_policies.SimpleWALRetentionPolicy(context, policy, server)View on GitHub#

Bases: RetentionPolicy

Simple retention policy for WAL files (identical to the main one)

__init__(context, policy, server)View on GitHub#

Constructor of the retention policy base class

_abc_impl = <_abc._abc_data object>#
_backup_report(source)View on GitHub#

Report obsolete/valid backups according to the retention policy

_re = re.compile('^\\s*main\\s*$', re.IGNORECASE)#
_wal_report()View on GitHub#

Report obsolete/valid backups according to the retention policy

classmethod create(server, context, optval)View on GitHub#

If given option and value from the configuration file match, creates the retention policy object for the given server

debug()View on GitHub#

Debug information

first_wal()View on GitHub#

Returns the first valid WAL according to retention policies