Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple / variable backup times. #111

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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