Puppet Class: borg::config

Defined in:
manifests/config.pp

Overview

Parameters:

  • default_version (Pattern[/^\d*\.\d*\.\d*$/]) (defaults to: '1.2.0')


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'manifests/config.pp', line 2

class borg::config (
  Pattern[/^\d*\.\d*\.\d*$/] $default_version = '1.2.0',
) {
  assert_private()

  $backupdestdir = $borg::absolutebackupdestdir ? {
    Undef   => "${borg::username}/${borg::backupdestdir}",
    default => $borg::absolutebackupdestdir,
  }
  $numeric = versioncmp(pick(fact('borgbackup.version'), $default_version), '1.2.0') ? {
    -1      => '--numeric-owner',
    default => '--numeric-ids',
  }

  # script to run the backup
  file { '/usr/local/bin/borg-backup':
    ensure  => 'file',
    content => epp("${module_name}/borg-backup.sh.epp",
      {
        'manage_prune'       => $borg::manage_prune,
        'keep_within'        => $borg::keep_within,
        'keep_daily'         => $borg::keep_daily,
        'keep_weekly'        => $borg::keep_weekly,
        'keep_monthly'       => $borg::keep_monthly,
        'keep_yearly'        => $borg::keep_yearly,
        'compression'        => $borg::compression,
        'working_directory'  => $borg::working_directory,
        'backupdestdir'      => $backupdestdir,
        'backupdatadir'      => $borg::backupdatadir,
        'pre_backup_script'  => $borg::pre_backup_script,
        'post_backup_script' => $borg::post_backup_script,
        'numeric'            => $numeric,
        'upload_ratelimit'   => $borg::upload_ratelimit,
    }),
    mode    => '0755',
    owner   => 'root',
    group   => 'root',
  }

  $ensure = $facts['os']['name'] ? {
    'Archlinux' => 'absent',
    default     => 'file'
  }

  # setup the config for the restore script
  file { '/etc/borg-restore.cfg':
    ensure  => 'file',
    content => epp("${module_name}/borg-restore.cfg.epp", { 'backupdestdir' => $backupdestdir, }),
  }
  # config file is deprecated and should be absent
  file { '/etc/backup-sh-conf.sh':
    ensure  => 'absent',
  }
  # create the backup key for a user
  ssh_keygen { 'root_borg':
    type     => $borg::ssh_key_type,
    filename => "/root/.ssh/id_${borg::ssh_key_type}_borg",
    home     => '/root',
    user     => 'root',
  }

  # /root/.ssh/config entry for the backup server
  if $borg::ssh_proxyjump {
    ssh::client::config::user { 'root':
      ensure        => present,
      user_home_dir => '/root',
      options       => {
        'Host backup' => {
          'User'         => $borg::username,
          'IdentityFile' => "~/.ssh/id_${borg::ssh_key_type}_borg",
          'Hostname'     => $borg::backupserver,
          'Port'         => $borg::ssh_port,
          'ProxyJump'    => $borg::ssh_proxyjump,
        },
      },
    }
  } else {
    ssh::client::config::user { 'root':
      ensure        => present,
      user_home_dir => '/root',
      options       => {
        'Host backup' => {
          'User'         => $borg::username,
          'IdentityFile' => "~/.ssh/id_${borg::ssh_key_type}_borg",
          'Hostname'     => $borg::backupserver,
          'Port'         => $borg::ssh_port,
        },
      },
    }
  }
}