Skip to content

Commit

Permalink
Added support for multiple / variable backup times.
Browse files Browse the repository at this point in the history
Fixes #91
replaces #92

This now looks as this:

```
--- /etc/systemd/system/borg-backup.timer	2021-07-12 13:35:20.895432545 +0200
+++ /tmp/puppet-file20210720-108100-1p92i82	2021-07-20 09:46:01.670324290 +0200
@@ -1,11 +1,11 @@
 # THIS FILE IS MANAGED BY PUPPET
 [Unit]
-Description=Daily Timer for borg-backup
+Description=Daily Timer(s) for borg-backup

 [Timer]
 # OnBootSec=10min
 # OnUnitActiveSec=1d
-# Daily at 8am
+# Daily named job "default" at 18:30:00
 OnCalendar=*-*-* 18:30:00
 Persistent=True
```
  • Loading branch information
sebastianberm authored and bastelfreak committed Jul 20, 2021
1 parent df9fdfb commit 7f70c7d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ The following parameters are available in the `borg` class:
* [`proxy_server`](#proxy_server)
* [`manage_package`](#manage_package)
* [`ssh_key_type`](#ssh_key_type)
* [`backuptime`](#backuptime)

##### <a name="package_name"></a>`package_name`

Expand Down Expand Up @@ -297,3 +298,11 @@ configure your most favourite ssh key type. This will be used to connect to the

Default value: `'ed25519'`

##### <a name="backuptime"></a>`backuptime`

Data type: `Hash[String[1],String[1]]`

Configure the name of each backupjob and the time of that job.

Default value: `{ 'default' => '18:30:00' }`

4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
# @param ssh_key_type
# configure your most favourite ssh key type. This will be used to connect to the remote borg server.
#
# @param backuptime
# Configure the name of each backupjob and the time of that job.
#
# @see https://metacpan.org/pod/App::BorgRestore
#
class borg (
Expand Down Expand Up @@ -127,6 +130,7 @@
Optional[String[1]] $proxy_server = undef,
Boolean $manage_package = true,
Enum['rsa', 'ed25519'] $ssh_key_type = 'ed25519',
Hash[String[1],String[1]] $backuptime = { 'default' => '18:30:00' },
) {
contain borg::install
contain borg::config
Expand Down
8 changes: 5 additions & 3 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
),
}
-> systemd::unit_file { 'borg-backup.timer':
content => epp("${module_name}/borg-backup.timer.epp"),
enable => true,
active => true,
content => epp("${module_name}/borg-backup.timer.epp",
backuptime => $borg::backuptime
),
enable => true,
active => true,
}
}
}
33 changes: 33 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,39 @@

it { is_expected.to compile.with_all_deps }
end

context 'fails without a valid backuptime present' do
let :params do
{
backupserver: 'localhost',
backuptime: ''
}
end

it { is_expected.not_to compile }
end

context 'with nondefault backuptime present' do
let :params do
{
backupserver: 'localhost',
backuptime: { 'default' => '01:00:00' }
}
end

it { is_expected.to compile.with_all_deps }
end

context 'with multiple backuptimes present' do
let :params do
{
backupserver: 'localhost',
backuptime: { '1 am' => '01:00:00', '2 am' => '02:00:00' }
}
end

it { is_expected.to compile.with_all_deps }
end
end
end
end
10 changes: 7 additions & 3 deletions templates/borg-backup.timer.epp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<%- | Hash[String,String] $backuptime,
| -%>
# THIS FILE IS MANAGED BY PUPPET
[Unit]
Description=Daily Timer for borg-backup
Description=Daily Timer(s) for borg-backup

[Timer]
# OnBootSec=10min
# OnUnitActiveSec=1d
# Daily at 8am
OnCalendar=*-*-* 18:30:00
<% $backuptime.each | $jobname, $time | { -%>
# Daily named job "<%= $jobname %>" at <%= $time %>
OnCalendar=*-*-* <%= $time %>
<% } -%>
Persistent=True

[Install]
Expand Down

0 comments on commit 7f70c7d

Please sign in to comment.