Puppet Class: barman

Defined in:
manifests/init.pp

Overview

Authors

  • Giuseppe Broccolo <giuseppe.broccolo@2ndQuadrant.it>

  • Giulio Calacoci <giulio.calacoci@2ndQuadrant.it>

  • Francesco Canovai <francesco.canovai@2ndQuadrant.it>

  • Marco Nenciarini <marco.nenciarini@2ndQuadrant.it>

  • Gabriele Bartolini <gabriele.bartolini@2ndQuadrant.it>

  • Alessandro Grassi <alessandro.grassi@2ndQuadrant.it>

Many thanks to Alessandro Franceschi <al@lab42.it>

Copyright 2012-2017 2ndQuadrant Italia

This option allows you to enable data compression for network transfers. Defaults to false. One or more absolute paths, separated by colon, where Barman

looks for executable files.

Hook script launched after a WAL file is

archived by maintenance. Being this a retry hook
script, Barman will retry the execution of the
script until this either returns a SUCCESS (0),
an ABORT_CONTINUE (62) or an ABORT_STOP (63)
code. In a post archive scenario, ABORT_STOP has
currently the same effects as ABORT_CONTINUE.

Hook script launched after a WAL file is archived by

maintenance, after 'post_archive_retry_script'.

Hook script launched after a base backup. Being

this a retry hook script, Barman will retry the
execution of the script until this either returns
a SUCCESS (0), an ABORT_CONTINUE (62) or an
ABORT_STOP (63) code. In a post backup scenario,
ABORT_STOP has currently the same effects as
ABORT_CONTINUE.

Hook script launched after a base backup, after

'post_backup_retry_script'.

Hook script launched before a WAL file is

archived by maintenance, after
'pre_archive_script'. Being this a retry hook
script, Barman will retry the execution of the
script until this either returns a SUCCESS (0),
an ABORT_CONTINUE (62) or an ABORT_STOP (63)
code. Returning ABORT_STOP will propagate the
failure at a higher level and interrupt the WAL
archiving operation.

Hook script launched before a WAL file is archived by maintenance. Hook script launched before a base backup, after

'pre_backup_script'. Being this a retry hook
script, Barman will retry the execution of the
script until this either returns a SUCCESS (0), an
ABORT_CONTINUE (62) or an ABORT_STOP (63) code.
Returning ABORT_STOP will propagate the failure at
a higher level and interrupt the backup operation.

Hook script launched before a base backup. Base backup retention policy, based on redundancy or

recovery window. Default empty (no retention enforced).
Value must be greater than or equal to the server
minimum redundancy level (if not is is assigned to
that value and a warning is generated).

WAL archive logs retention policy. Currently, the

only allowed value for wal_retention_policy is the
special value main, that maps the retention policy
of archive logs to that of base backups.

Can only be set to auto (retention policies are

automatically enforced by the barman cron command)

Incremental backup is a kind of full periodic backup which

saves only data changes from the latest full backup
available in the catalogue for a specific PostgreSQL
server. Disabled if false. Default false.

Physical replication slot to be used by the receive-wal

command when streaming_archiver is set to on. Requires
postgreSQL >= 9.4. Default: undef (disabled).

This option allows you to use the PostgreSQL’s

streaming protocol to receive transaction logs from a
server. This activates connection checks as well as
management (including compression) of WAL files. If
set to off (default) barman will rely only on
continuous archiving for a server WAL archive
operations, eventually terminating any running
pg_receivexlog for the server.

This option allows you to activate batch

processing of WAL files for the
streaming_archiver process, by setting it to
a value > 0. Otherwise, the traditional
unlimited processing of the WAL queue is
enabled.

Identifier to be used as application_name by the

receive-wal command. Only available with
pg_receivexlog >= 9.3. By default it is set to
barman_receive_wal.

Identifier to be used as application_name by the

pg_basebackup command. Only available with
pg_basebackup >= 9.3. By default it is set to
barman_streaming_backup.

Directory where WAL files are streamed from the

PostgreSQL server to Barman.

This option allows you to specify a maximum

transfer rate in kilobytes per second, by
specifying a comma separated list of
tablespaces (pairs TBNAME:BWLIMIT). A value of
zero specifies no limit (default).

DEPRECATED. Custom configuration directives (e.g. for

custom compression). Defaults to empty.

The fqdn of the Barman server. It will be exported in

several resources in the PostgreSQL server. Puppet
automatically set this.

This is the main parameter to enable the

autoconfiguration of the backup of a given PostgreSQL
server. Defaults to false.

The ipaddress exported to the PostgreSQL server

during atutoconfiguration. Defaults to
"${::ipaddress}/32".

Configure PGDG repository. It is implemented

internally by declaring the `postgresql::globals`
class. If you need to customize the
`postgresql::globals` class declaration, keep the
`manage_package_repo` parameter disabled in `barman`
module and enable it directly in
`postgresql::globals` class.

When using autoconfigure, ensure the hosts contain

each other ssh host key. Must also be set on
'barman::postgres' class. Defaults to false.

Whether or not barman conf files not included in

puppetdb will be removed by puppet.

hiera hash to support the server define.

Defaults to undef.

Examples:

The class can be used right away with defaults:


include barman

All parameters that are supported by barman can be changed:

class { barman:
  logfile  => '/var/log/barman/something_else.log',
  compression => 'bzip2',
  pre_backup_script => '/usr/bin/touch /tmp/started',
  post_backup_script => '/usr/bin/touch /tmp/stopped',
  custom_lines => '; something'
}

Parameters:

  • user (String)

    The Barman user. Default ‘barman`.

  • group (String)

    The group of the Barman user

  • ensure (String)

    Ensure that Barman is installed. The default value is ‘present’. Otherwise it will be set as ‘absent’.

  • dbuser (String)

    Username used for connecting to the database

  • dbname (String)
  • conf_file_path (String) (defaults to: $barman::conf_file_path)

    Absolute path to main ‘barman.conf` file

  • conf_template (String) (defaults to: 'barman/barman.conf.erb')

    Path of the template of the barman.conf configuration

    file. The default value does not need to be changed.
    
  • logrotate_template (String) (defaults to: 'barman/logrotate.conf.erb')

    Path of the template of the logrotate.conf file. The default value does not need to be changed.

  • home (Stdlib::Absolutepath)

    A different place for backups than the default. Will be symlinked to the default (/var/lib/barman). You should not change this

    value after the first setup.
    
  • home_mode (String)

    Directory mode, default: ‘0750`

  • logfile (Stdlib::Absolutepath)

    A different log file. The default is ‘/var/log/barman/barman.log’

  • log_level (Barman::LogLevel)

    Level of logging. The default is INFO (DEBUG, INFO, WARNING, ERROR, CRITICAL). Global.

  • archiver (Boolean)

    Whether the log shipping backup mechanism is active or not (defaults to true)

  • archive_cmd_type (String)

    Default ‘rsync`

  • hba_entry_order (Integer)

    Entry priority

  • archiver_batch_size (Optional[Integer]) (defaults to: undef)

    Setting this option enables batch processing of WAL files. The default processes all currently available files.

  • backup_method (Barman::BackupMethod) (defaults to: undef)

    Configure the method barman used for backup execution. If set to rsync (default), barman will execute backup using the rsync command. If set to postgres barman will use the pg_basebackup command to execute the backup.

  • backup_options (Barman::BackupOptions) (defaults to: undef)

    Behavior for backup operations: possible values are exclusive_backup (default) and concurrent_backup.

  • recovery_options (Barman::RecoveryOptions) (defaults to: undef)

    The restore command to write in the recovery.conf. Possible values are ‘get-wal’ and undef. Default: undef.

  • bandwidth_limit (Optional[Integer]) (defaults to: undef)

    This option allows you to specify a maximum transfer rate in kilobytes per second. A value of zero specifies no limit (default).

  • barman_lock_directory (Optional[String]) (defaults to: undef)

    Global option for a directory for lock files.

  • check_timeout (Optional[Integer]) (defaults to: undef)

    Maximum execution time, in seconds per server, for a barman check command. Set to 0 to disable the timeout. Positive integer, default 30.

  • compression (Variant[String,Boolean])

    Compression algorithm. Currently supports ‘gzip’ (default), ‘bzip2’, and ‘custom’. Disabled if false.

  • create_slot (Barman::CreateSlot) (defaults to: undef)

    Determines whether Barman should automatically create a replication slot if it’s not already present for streaming WAL files. One of ‘auto’ or ‘manual’ (default).

  • custom_compression_filter (Optional[String]) (defaults to: undef)

    Customised compression algorithm applied to WAL files.

  • custom_decompression_filter (Optional[String]) (defaults to: undef)

    Customised decompression algorithm applied to compressed WAL files; this must match the compression algorithm.

  • immediate_checkpoint (Boolean)

    Force the checkpoint on the Postgres server to happen immediately and start your backup copy process as soon as possible. Disabled if false (default)

  • basebackup_retry_times (Optional[Integer]) (defaults to: undef)

    Number of retries fo data copy during base backup after an error. Default = 0

  • basebackup_retry_sleep (Optional[Integer]) (defaults to: undef)

    Number of seconds to wait after after a failed copy, before retrying. Default = 30

  • minimum_redundancy (Integer)

    Minimum number of required backups (redundancy). Default = 0

  • network_compression (Optional[Boolean]) (defaults to: undef)
  • parallel_jobs (Optional[Integer]) (defaults to: undef)

    Number of parallel workers used to copy files during backup or recovery. Requires backup mode = rsync.

  • path_prefix (Optional[Stdlib::Absolutepath]) (defaults to: undef)
  • last_backup_maximum_age (Barman::BackupAge) (defaults to: undef)

    Defines the time frame within which the latest backup must fall. If the latest backup is older than this period, the barman check command will report an error. If left empty (default), the latest backup is always considered valid. The accepted format is “n DAYS|WEEKS|MONTHS”, where n is an integer greater than zero.

  • last_wal_maximum_age (Barman::BackupAge) (defaults to: undef)

    Defines the time frame within which the latest archived WAL file must fall. If the latest WAL file is older than this period, the barman check command will report an error. If left empty (default), the age of the WAL files is not checked. Format is the same as last_backup_maximum_age.

  • last_backup_minimum_size (Barman::BackupSize) (defaults to: undef)

    Specifies the minimum acceptable size for the latest successful backup. If the latest backup is smaller than this size, the barman check command will report an error. If left empty (default), the latest backup is always considered valid. The accepted format is “n k|Ki|M|Mi|G|Gi|T|Ti” and case-sensitive, where n is an integer greater than zero, with an optional SI or IEC suffix. k stands for kilo with k = 1000, while Ki stands for kilobytes Ki = 1024. The rest of the options have the same reasoning for greater units of measure.

  • post_archive_retry_script (Optional[String]) (defaults to: undef)
  • post_archive_script (Optional[String]) (defaults to: undef)
  • post_backup_retry_script (Optional[String]) (defaults to: undef)
  • post_backup_script (Optional[String]) (defaults to: undef)
  • pre_archive_retry_script (Optional[String]) (defaults to: undef)
  • pre_archive_script (Optional[String]) (defaults to: undef)
  • pre_backup_retry_script (Optional[String]) (defaults to: undef)
  • pre_backup_script (Optional[String]) (defaults to: undef)
  • retention_policy (Barman::RetentionPolicy) (defaults to: undef)
  • wal_retention_policy (Barman::WalRetention) (defaults to: undef)
  • retention_policy_mode (Barman::RetentionPolicyMode) (defaults to: undef)
  • reuse_backup (Barman::ReuseBackup) (defaults to: undef)
  • slot_name (Optional[String]) (defaults to: undef)
  • streaming_archiver (Boolean)
  • streaming_archiver_batch_size (Optional[Integer]) (defaults to: undef)
  • streaming_archiver_name (Optional[String]) (defaults to: undef)
  • streaming_backup_name (Optional[String]) (defaults to: undef)
  • streaming_wals_directory (Optional[Stdlib::Absolutepath]) (defaults to: undef)
  • tablespace_bandwidth_limit (Optional[String]) (defaults to: undef)
  • custom_lines (Optional[String]) (defaults to: undef)
  • barman_fqdn (String) (defaults to: $facts['networking']['fqdn'])
  • autoconfigure (Boolean)
  • exported_ipaddress (Stdlib::IP::Address) (defaults to: "${facts['networking']['ip']}/32")
  • host_group (String)

    Tag used to collect and export resources during

    autoconfiguration. Defaults to 'global'.
    
  • manage_package_repo (Boolean)
  • manage_ssh_host_keys (Boolean)
  • purge_unknown_conf (Boolean)
  • servers (Optional[Hash]) (defaults to: undef)


279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'manifests/init.pp', line 279

class barman (
  String                             $user,
  String                             $group,
  String                             $ensure,
  Boolean                            $archiver,
  Boolean                            $autoconfigure,
  Variant[String,Boolean]            $compression,
  String                             $dbuser,
  Stdlib::Absolutepath               $home,
  String                             $home_mode,
  String                             $host_group,
  String                             $dbname,
  Boolean                            $immediate_checkpoint,
  Stdlib::Absolutepath               $logfile,
  Barman::LogLevel                   $log_level,
  Boolean                            $manage_package_repo,
  Boolean                            $manage_ssh_host_keys,
  Integer                            $minimum_redundancy,
  Boolean                            $purge_unknown_conf,
  Boolean                            $streaming_archiver,
  String                             $archive_cmd_type,
  Integer                            $hba_entry_order,
  String                             $conf_file_path                = $barman::conf_file_path,
  String                             $conf_template                 = 'barman/barman.conf.erb',
  String                             $logrotate_template            = 'barman/logrotate.conf.erb',
  String                             $barman_fqdn                   = $facts['networking']['fqdn'],
  Optional[Integer]                  $archiver_batch_size           = undef,
  Barman::BackupMethod               $backup_method                 = undef,
  Barman::BackupOptions              $backup_options                = undef,
  Optional[Integer]                  $bandwidth_limit               = undef,
  Optional[String]                   $barman_lock_directory         = undef,
  Optional[Integer]                  $basebackup_retry_sleep        = undef,
  Optional[Integer]                  $basebackup_retry_times        = undef,
  Optional[Integer]                  $check_timeout                 = undef,
  Barman::CreateSlot                 $create_slot                   = undef,
  Optional[String]                   $custom_compression_filter     = undef,
  Optional[String]                   $custom_decompression_filter   = undef,
  Stdlib::IP::Address                $exported_ipaddress            = "${facts['networking']['ip']}/32",
  Barman::BackupAge                  $last_backup_maximum_age        = undef,
  Barman::BackupAge                  $last_wal_maximum_age           = undef,
  Barman::BackupSize                 $last_backup_minimum_size       = undef,
  Optional[Boolean]                  $network_compression            = undef,
  Optional[Integer]                  $parallel_jobs                  = undef,
  Optional[Stdlib::Absolutepath]     $path_prefix                    = undef,
  Optional[String]                   $post_archive_retry_script      = undef,
  Optional[String]                   $post_archive_script            = undef,
  Optional[String]                   $post_backup_retry_script       = undef,
  Optional[String]                   $post_backup_script             = undef,
  Optional[String]                   $pre_archive_retry_script       = undef,
  Optional[String]                   $pre_archive_script             = undef,
  Optional[String]                   $pre_backup_retry_script        = undef,
  Optional[String]                   $pre_backup_script              = undef,
  Barman::RecoveryOptions            $recovery_options               = undef,
  Barman::RetentionPolicy            $retention_policy               = undef,
  Barman::RetentionPolicyMode        $retention_policy_mode          = undef,
  Barman::ReuseBackup                $reuse_backup                   = undef,
  Optional[String]                   $slot_name                      = undef,
  Optional[Integer]                  $streaming_archiver_batch_size  = undef,
  Optional[String]                   $streaming_archiver_name        = undef,
  Optional[String]                   $streaming_backup_name          = undef,
  Optional[String]                   $tablespace_bandwidth_limit     = undef,
  Barman::WalRetention               $wal_retention_policy           = undef,
  Optional[String]                   $custom_lines                   = undef,
  Optional[Hash]                     $servers                        = undef,
  Optional[Stdlib::Absolutepath]     $streaming_wals_directory       = undef,
) {
  # when hash data is in servers, then fire-off barman::server define with that hash data
  if ($servers) {
    create_resources('barman::server', deep_merge(hiera_hash('barman::servers', {}), $servers))
  }

  # Ensure creation (or removal) of Barman files and directories
  $ensure_file = $ensure ? {
    'absent' => 'absent',
    default  => 'present',
  }
  $ensure_directory = $ensure ? {
    'absent' => 'absent',
    default  => 'directory',
  }

  if $manage_package_repo {
    if defined(Class['postgresql::globals']) {
      fail('Class postgresql::globals is already defined. Set barman class manage_package_repo parameter to false (preferred) or remove the other definition.')
    } else {
      class { 'postgresql::globals':
        manage_package_repo => true,
      }
    }
  }
  package { 'barman':
    ensure => $ensure,
    tag    => 'postgresql',
  }

  file { '/etc/barman.d':
    ensure  => $ensure_directory,
    purge   => $purge_unknown_conf,
    recurse => true,
    owner   => 'root',
    group   => $group,
    mode    => '0750',
    require => Package['barman'],
  }

  if $conf_file_path == '/etc/barman/barman.conf' {
    file { '/etc/barman':
      ensure  => $ensure_directory,
      purge   => $purge_unknown_conf,
      recurse => true,
      owner   => 'root',
      group   => $group,
      mode    => '0750',
      require => Package['barman'],
    }

    file { $conf_file_path:
      ensure  => $ensure_file,
      owner   => 'root',
      group   => $group,
      mode    => '0640',
      content => template($conf_template),
      require => File['/etc/barman'],
    }
  } else {
    file { $conf_file_path:
      ensure  => $ensure_file,
      owner   => 'root',
      group   => $group,
      mode    => '0640',
      content => template($conf_template),
    }
  }

  file { $home:
    ensure  => $ensure_directory,
    owner   => $user,
    group   => $group,
    mode    => $home_mode,
    require => Package['barman'],
  }

  if $manage_ssh_host_keys {
    file { "${home}/.ssh":
      ensure  => directory,
      owner   => $user,
      group   => $group,
      mode    => '0700',
      require => File[$home],
    }

    file { "${home}/.ssh/known_hosts":
      ensure => file,
      owner  => $user,
      group  => $group,
      mode   => '0600',
    }
  }

  # Run 'barman check all' to create Barman backup directories
  exec { 'barman-check-all':
    command     => '/usr/bin/barman check all',
    subscribe   => File[$home],
    refreshonly => true,
  }

  file { '/etc/logrotate.d/barman':
    ensure  => $ensure_file,
    owner   => 'root',
    group   => 0,
    mode    => '0644',
    content => template($logrotate_template),
    require => Package['barman'],
  }

  # Set the autoconfiguration
  if $autoconfigure {
    class { 'barman::autoconfigure':
      exported_ipaddress => $exported_ipaddress,
      host_group         => $host_group,
      archive_cmd_type   => $archive_cmd_type,
    }
  }
}