Defined Type: duplicity::profile

Defined in:
manifests/profile.pp

Overview

Class: duplicity::profile

Configure a backup profile.

Parameters

ensure

Set state the profile should be in. Either present or absent.

gpg_encryption

Enable or disable GPG encryption of backups. Defaults to ‘true’.

gpg_encryption_keys

List of public keyids used to encrypt the backup.

gpg_signing_key

Set the keyid of the key used to sign the backup.

gpg_passphrase

Set the passphrase needed for signing, decryption and symmetric encryption.

gpg_options

List of options passed from duplicity to the gpg process.

source

Set the base directory to backup. Defaults to the root directory of the filesystem.

target

Set the target where to store / find the backups. Expected to be an url like scheme://host/[/]path.

target_username

Set the username used to authenticate with the target.

target_password

Set the password to authenticate the username at the target.

full_if_older_than

Forces a full backup if last full backup reaches a specified age.

volsize

Set the size of backup chunks in MBs.

include_filelist

List of files to be included in the backup.

exclude_filelist

List of files to be excluded from the backup. Paths can be relative like ‘**/cache’.

exclude_content

Raw content to set as the exclude file list. See ‘man 1 duplicity’, section ‘FILE SELECTION’.

exclude_by_default

Exclude any file relative to the source directory that is not included; sets the ‘- **’ parameter.

cron_enabled

Set the state of the cron job. Either true or false.

cron_hour

The hour expression of the cron job.

cron_minute

The minute expression of the cron job.

duply_version

Deprecated, will be removed in the next major release.

duply_environment

An array of extra environment variables to pass to duplicity.

duplicity_extra_params

An array of extra parameters to pass to duplicity.

duply_custom_batch

Custom batch command for Duply cron job. Batch format is ‘<command>[<command>…]’ check Duply man page for details. Leave undefined for default batch: ‘cleanup_backup_purgeFull’

exec_before_content

Content to be added to the pre-backup script

exec_before_source

Source file to be used as the pre-backup script

exec_after_content

Content to be added to the post-backup script

exec_after_source

Source file to be used as the post-backup script

niceness

Nice value, -20 (most favorable scheduling) to 19 (least favorable) - disabled by default

max_fulls_with_incrs

Number of full backups for which incrementals should be kept

max_full_backups

Number of full backups to keep

max_age

Maximum amount of time for which backups should be kept, e.g. 12M

Authors

Martin Meinhold <Martin.Meinhold@gmx.de>

Copyright 2014 Martin Meinhold, unless otherwise noted.

Parameters:

  • ensure (Enum['present', 'absent']) (defaults to: present)
  • gpg_encryption (Boolean) (defaults to: true)
  • gpg_encryption_keys (Variant[String, Array[String]]) (defaults to: $duplicity::gpg_encryption_keys)
  • gpg_signing_key (String) (defaults to: $duplicity::gpg_signing_key)
  • gpg_passphrase (String) (defaults to: $duplicity::gpg_passphrase)
  • gpg_options (Variant[String, Array[String]]) (defaults to: $duplicity::gpg_options)
  • target (String) (defaults to: "${duplicity::backup_target_url}/${title}")
  • target_username (String) (defaults to: $duplicity::backup_target_username)
  • target_password (String) (defaults to: $duplicity::backup_target_password)
  • source (String) (defaults to: '/')
  • full_if_older_than (Variant[Integer, String]) (defaults to: '')
  • max_full_backups (Variant[Integer, String]) (defaults to: '')
  • max_fulls_with_incrs (Variant[Integer, String]) (defaults to: '')
  • max_age (String) (defaults to: '')
  • volsize (Integer) (defaults to: 50)
  • include_filelist (Array[String]) (defaults to: [])
  • exclude_filelist (Array[String ]) (defaults to: [])
  • exclude_content (Optional[String]) (defaults to: undef)
  • exclude_by_default (Boolean) (defaults to: true)
  • cron_enabled (Boolean) (defaults to: $duplicity::cron_enabled)
  • cron_hour (Optional[Variant[Integer, String, Array]]) (defaults to: undef)
  • cron_minute (Optional[Variant[Integer, String]]) (defaults to: undef)
  • duply_version (Optional[String]) (defaults to: undef)
  • duply_environment (Array[String]) (defaults to: $duplicity::duply_environment)
  • duplicity_extra_params (Array[String]) (defaults to: $duplicity::duplicity_extra_params)
  • duply_cache_dir (Optional[Stdlib::Absolutepath]) (defaults to: $duplicity::duply_cache_dir)
  • duply_temp_dir (Optional[Stdlib::Absolutepath]) (defaults to: $duplicity::duply_temp_dir)
  • duply_custom_batch (Optional[String]) (defaults to: undef)
  • exec_before_content (Optional[String]) (defaults to: undef)
  • exec_before_source (Optional[String]) (defaults to: undef)
  • exec_after_content (Optional[String]) (defaults to: undef)
  • exec_after_source (Optional[String]) (defaults to: undef)
  • niceness (Optional[Integer]) (defaults to: undef)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
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
# File 'manifests/profile.pp', line 108

define duplicity::profile(
  Enum['present', 'absent'] $ensure = present,
  Boolean $gpg_encryption = true,
  Variant[String, Array[String]] $gpg_encryption_keys = $duplicity::gpg_encryption_keys,
  String $gpg_signing_key = $duplicity::gpg_signing_key,
  String $gpg_passphrase = $duplicity::gpg_passphrase,
  Variant[String, Array[String]] $gpg_options = $duplicity::gpg_options,
  String $target = "${duplicity::backup_target_url}/${title}",
  String $target_username = $duplicity::backup_target_username,
  String $target_password = $duplicity::backup_target_password,
  String $source = '/',
  Variant[Integer, String] $full_if_older_than = '',
  Variant[Integer, String] $max_full_backups = '',
  Variant[Integer, String] $max_fulls_with_incrs = '',
  String $max_age = '',
  Integer $volsize = 50,
  Array[String] $include_filelist = [],
  Array[String ] $exclude_filelist = [],
  Optional[String] $exclude_content = undef,
  Boolean $exclude_by_default = true,
  Boolean $cron_enabled = $duplicity::cron_enabled,
  Optional[Variant[Integer, String, Array]] $cron_hour = undef,
  Optional[Variant[Integer, String]] $cron_minute = undef,
  Optional[String] $duply_version = undef,
  Array[String] $duply_environment = $duplicity::duply_environment,
  Array[String] $duplicity_extra_params = $duplicity::duplicity_extra_params,
  Optional[Stdlib::Absolutepath] $duply_cache_dir = $duplicity::duply_cache_dir,
  Optional[Stdlib::Absolutepath] $duply_temp_dir = $duplicity::duply_temp_dir,
  Optional[String] $duply_custom_batch = undef,
  Optional[String] $exec_before_content = undef,
  Optional[String] $exec_before_source = undef,
  Optional[String] $exec_after_content = undef,
  Optional[String] $exec_after_source = undef,
  Optional[Integer] $niceness = undef,
) {
  require duplicity

  if !empty($gpg_signing_key) and $gpg_signing_key !~ /^[a-zA-Z0-9]+$/ {
    fail("Duplicity::Profile[${title}]: signing_key must be alphanumeric, got '${gpg_signing_key}'")
  }

  if $ensure == 'present' {
    if empty($source) {
        fail("Duplicity::Profile[${title}]: source must not be empty")
    }

    if empty($target) {
      fail("Duplicity::Profile[${title}]: target must not be empty")
    }
  }

  $max_full_backups_str = String($max_full_backups)
  if !empty($max_full_backups_str) and "str${max_full_backups}" !~ /str[0-9]+/ {
    fail("Duplicity::Profile[${title}]: max_full_backups must be an integer, got '${max_full_backups}'")
  }

  $max_fulls_with_incrs_str = String($max_fulls_with_incrs)
  if !empty($max_fulls_with_incrs_str) and "str${max_fulls_with_incrs}" !~ /str[0-9]+/ {
    fail("Duplicity::Profile[${title}]: max_fulls_with_incrs must be an integer, got '${max_fulls_with_incrs}'")
  }

  if !empty($exclude_content) {
    if !empty($exclude_filelist) {
      fail("Duplicity::Profile[${title}]: exclude_content cannot be used together with exclude_filelist")
    }

    if !empty($include_filelist) {
      fail("Duplicity::Profile[${title}]: exclude_content cannot be used together with include_filelist")
    }
  }

  $real_duply_environment = empty($duply_environment) ? {
    true    => [],
    default => any2array($duply_environment)
  }

  $real_gpg_encryption_keys = empty($gpg_encryption_keys) ? {
    true    => [],
    default => any2array($gpg_encryption_keys)
  }
  $real_gpg_signing_keys = empty($gpg_signing_key) ? {
    true    => [],
    default => any2array($gpg_signing_key)
  }
  $real_gpg_options = empty($gpg_options) ? {
    true    => [],
    default => any2array($gpg_options)
  }
  $real_duplicity_params = empty($duplicity_extra_params) ? {
    true    => [],
    default => any2array($duplicity_extra_params)
  }

  $profile_config_dir = "${duplicity::params::duply_config_dir}/${title}"
  $profile_config_dir_ensure = $ensure ? {
    'absent' => 'absent',
    default  => 'directory',
  }
  $profile_config_file = "${profile_config_dir}/conf"
  $profile_filelist_file = "${profile_config_dir}/${duplicity::params::duply_profile_filelist_name}"
  $profile_include_filelist = join(regsubst($include_filelist, '^(.+)$', "+ \\1\n"), '')
  $profile_exclude_filelist = join(regsubst($exclude_filelist, '^(.+)$', "- \\1\n"), '')
  $profile_pre_script = "${profile_config_dir}/${duplicity::params::duply_profile_pre_script_name}"
  $profile_post_script = "${profile_config_dir}/${duplicity::params::duply_profile_post_script_name}"
  $profile_file_ensure = $ensure ? {
    'absent' => 'absent',
    default  => 'file',
  }
  $profile_concat_ensure = $ensure ? {
    'absent' => 'absent',
    default  => 'present',
  }
  $cron_ensure = str2bool($cron_enabled) ? {
    false   => 'absent',
    default => 'present',
  }
  $exclude_by_default_ensure = $exclude_by_default ? {
    true    => 'present',
    default => 'absent',
  }
  $complete_encryption_keys = prefix($real_gpg_encryption_keys, "${title}/")
  $complete_signing_keys = prefix($real_gpg_signing_keys, "${title}/")

  file { $profile_config_dir:
    ensure => $profile_config_dir_ensure,
    owner  => 'root',
    group  => 'root',
    mode   => '0700',
  }

  file { $profile_config_file:
    ensure    => $profile_file_ensure,
    content   => template('duplicity/etc/duply/conf.erb'),
    owner     => 'root',
    group     => 'root',
    mode      => '0400',
    show_diff => false,
  }

  concat { $profile_filelist_file:
    ensure         => $profile_concat_ensure,
    owner          => 'root',
    group          => 'root',
    mode           => '0400',
    ensure_newline => true,
  }

  concat::fragment { "${profile_filelist_file}/header":
    target  => $profile_filelist_file,
    content => template('duplicity/etc/duply/exclude.erb'),
    order   => '01',
  }

  if !empty($profile_exclude_filelist) {
    concat::fragment { "${profile_filelist_file}/exclude":
      target  => $profile_filelist_file,
      content => $profile_exclude_filelist,
      order   => '10',
    }
  }

  if !empty($profile_include_filelist) {
    concat::fragment { "${profile_filelist_file}/include":
      target  => $profile_filelist_file,
      content => $profile_include_filelist,
      order   => '50',
    }
  }

  if !empty($exclude_content) {
    concat::fragment { "${profile_filelist_file}/content":
      target  => $profile_filelist_file,
      content => $exclude_content,
      order   => '70',
    }
  }

  if $exclude_by_default_ensure == present {
    concat::fragment { "${profile_filelist_file}/exclude-by-default":
      target  => $profile_filelist_file,
      content => "\n- **\n",
      order   => '90',
    }
  }

  concat { $profile_pre_script:
    ensure         => $profile_concat_ensure,
    owner          => 'root',
    group          => 'root',
    mode           => '0700',
    ensure_newline => true,
  }

  if ! $exec_before_source {
    duplicity::profile_exec_before { "${title}/header":
      profile => $title,
      content => "#!/bin/bash\n",
      order   => '01',
    }
  }
  if $exec_before_content or $exec_before_source {
    duplicity::profile_exec_before { "${title}/content":
      profile => $title,
      content => $exec_before_content,
      source  => $exec_before_source,
    }
  }

  concat { $profile_post_script:
    ensure         => $profile_concat_ensure,
    owner          => 'root',
    group          => 'root',
    mode           => '0700',
    ensure_newline => true,
  }

  if ! $exec_after_source {
    duplicity::profile_exec_after { "${title}/header":
      profile => $title,
      content => "#!/bin/bash\n",
      order   => '01',
    }
  }
  if $exec_after_content or $exec_after_source {
    duplicity::profile_exec_after { "${title}/content":
      profile => $title,
      content => $exec_after_content,
      source  => $exec_after_source,
    }
  }

  duplicity::public_key_link { $complete_encryption_keys:
    ensure  => 'present',
  }

  duplicity::private_key_link { $complete_signing_keys:
    ensure  => 'present',
  }

  if $duply_custom_batch {
    $duply_batch = $duply_custom_batch
  }
  else {
    $duply_batch  = 'cleanup_backup_purgeFull'
  }

  if $duplicity::duply_log_output == 'logger' {
    $duply_command = "duply ${title} ${duply_batch} --force | logger -t \"${duplicity::duply_log_logger_tag}\""
  } else {
    $duply_command = "duply ${title} ${duply_batch} --force >> ${duplicity::duply_log_dir}/${title}.log"
  }

  if $niceness {
    $cron_command = "nice -n ${niceness} ${duply_command}"
  }
  else {
    $cron_command = $duply_command
  }


  cron { "backup-${title}":
    ensure      => $cron_ensure,
    command     => $cron_command,
    environment => "PATH=${duplicity::exec_path}",
    user        => 'root',
    hour        => $cron_hour,
    minute      => $cron_minute,
  }
}