Skip to content

Commit 6cc29dd

Browse files
author
carabasdaniel
authored
Merge pull request #1188 from syseleven/make_incremental_backups_deactivable
Make incremental backups deactivable
2 parents be17d0e + 155f8a1 commit 6cc29dd

File tree

3 files changed

+200
-67
lines changed

3 files changed

+200
-67
lines changed

manifests/backup/xtrabackup.pp

+25-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
$postscript = false,
2727
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
2828
$optional_args = [],
29-
$additional_cron_args = '--backup'
29+
$additional_cron_args = '--backup',
30+
$incremental_backups = true
3031
) inherits mysql::params {
3132

3233
ensure_packages($xtrabackup_package_name)
@@ -47,23 +48,36 @@
4748
}
4849
}
4950

50-
cron { 'xtrabackup-weekly':
51-
ensure => $ensure,
52-
command => "/usr/local/sbin/xtrabackup.sh --target-dir=${backupdir} ${additional_cron_args}",
53-
user => 'root',
54-
hour => $time[0],
55-
minute => $time[1],
56-
weekday => '0',
57-
require => Package[$xtrabackup_package_name],
51+
if $incremental_backups {
52+
cron { 'xtrabackup-weekly':
53+
ensure => $ensure,
54+
command => "/usr/local/sbin/xtrabackup.sh --target-dir=${backupdir} ${additional_cron_args}",
55+
user => 'root',
56+
hour => $time[0],
57+
minute => $time[1],
58+
weekday => '0',
59+
require => Package[$xtrabackup_package_name],
60+
}
61+
}
62+
63+
$daily_cron_data = ($incremental_backups) ? {
64+
true => {
65+
'directories' => "--incremental-basedir=${backupdir} --target-dir=${backupdir}/`date +%F_%H-%M-%S`",
66+
'weekday' => '1-6',
67+
},
68+
false => {
69+
'directories' => "--target-dir=${backupdir}",
70+
'weekday' => '*',
71+
},
5872
}
5973

6074
cron { 'xtrabackup-daily':
6175
ensure => $ensure,
62-
command => "/usr/local/sbin/xtrabackup.sh --incremental-basedir=${backupdir} --target-dir=${backupdir}/`date +%F_%H-%M-%S` ${additional_cron_args}",
76+
command => "/usr/local/sbin/xtrabackup.sh ${daily_cron_data['directories']} ${additional_cron_args}",
6377
user => 'root',
6478
hour => $time[0],
6579
minute => $time[1],
66-
weekday => '1-6',
80+
weekday => $daily_cron_data['weekday'],
6781
require => Package[$xtrabackup_package_name],
6882
}
6983

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
require 'spec_helper'
2+
3+
describe 'mysql::backup::xtrabackup' do
4+
on_supported_os.each do |os, facts|
5+
context "on #{os}" do
6+
let(:pre_condition) do
7+
<<-EOF
8+
class { 'mysql::server': }
9+
EOF
10+
end
11+
let(:facts) do
12+
facts.merge(root_home: '/root')
13+
end
14+
15+
let(:default_params) do
16+
{ 'backupdir' => '/tmp' }
17+
end
18+
19+
context 'with defaults' do
20+
let(:params) do
21+
default_params
22+
end
23+
24+
it 'contains the wrapper script' do
25+
is_expected.to contain_file('xtrabackup.sh').with_content(
26+
%r{(\n*^xtrabackup\s+.*\$@)},
27+
)
28+
end
29+
30+
it 'contains the weekly cronjob' do
31+
is_expected.to contain_cron('xtrabackup-weekly')
32+
.with(
33+
ensure: 'present',
34+
command: '/usr/local/sbin/xtrabackup.sh --target-dir=/tmp --backup',
35+
user: 'root',
36+
hour: '23',
37+
minute: '5',
38+
weekday: '0',
39+
)
40+
.that_requires('Package[percona-xtrabackup]')
41+
end
42+
43+
it 'contains the daily cronjob for weekdays 1-6' do
44+
is_expected.to contain_cron('xtrabackup-daily')
45+
.with(
46+
ensure: 'present',
47+
command: '/usr/local/sbin/xtrabackup.sh --incremental-basedir=/tmp --target-dir=/tmp/`date +%F_%H-%M-%S` --backup',
48+
user: 'root',
49+
hour: '23',
50+
minute: '5',
51+
weekday: '1-6',
52+
)
53+
.that_requires('Package[percona-xtrabackup]')
54+
end
55+
end
56+
57+
context 'with backupuser and backuppassword' do
58+
let(:params) do
59+
{ backupuser: 'backupuser',
60+
backuppassword: 'backuppassword' }.merge(default_params)
61+
end
62+
63+
it 'contains the defined mysql user' do
64+
is_expected.to contain_mysql_user('backupuser@localhost')
65+
.with(
66+
ensure: 'present',
67+
password_hash: '*4110E08DF51E70A4BA1D4E33A84205E38CF3FE58',
68+
)
69+
.that_requires('Class[mysql::server::root_password]')
70+
71+
is_expected.to contain_mysql_grant('backupuser@localhost/*.*')
72+
.with(
73+
ensure: 'present',
74+
user: 'backupuser@localhost',
75+
table: '*.*',
76+
privileges: ['RELOAD', 'PROCESS', 'LOCK TABLES', 'REPLICATION CLIENT'],
77+
)
78+
.that_requires('Mysql_user[backupuser@localhost]')
79+
end
80+
end
81+
82+
context 'with additional cron args' do
83+
let(:params) do
84+
{ additional_cron_args: '--backup --skip-ssl' }.merge(default_params)
85+
end
86+
87+
it 'contains the weekly cronjob' do
88+
is_expected.to contain_cron('xtrabackup-weekly')
89+
.with(
90+
ensure: 'present',
91+
command: '/usr/local/sbin/xtrabackup.sh --target-dir=/tmp --backup --skip-ssl',
92+
user: 'root',
93+
hour: '23',
94+
minute: '5',
95+
weekday: '0',
96+
)
97+
.that_requires('Package[percona-xtrabackup]')
98+
end
99+
100+
it 'contains the daily cronjob for weekdays 1-6' do
101+
is_expected.to contain_cron('xtrabackup-daily')
102+
.with(
103+
ensure: 'present',
104+
command: '/usr/local/sbin/xtrabackup.sh --incremental-basedir=/tmp --target-dir=/tmp/`date +%F_%H-%M-%S` --backup --skip-ssl',
105+
user: 'root',
106+
hour: '23',
107+
minute: '5',
108+
weekday: '1-6',
109+
)
110+
.that_requires('Package[percona-xtrabackup]')
111+
end
112+
end
113+
114+
context 'with deactivated incremental backups' do
115+
let(:params) do
116+
{ incremental_backups: false }.merge(default_params)
117+
end
118+
119+
it 'not contains the weekly cronjob' do
120+
is_expected.not_to contain_cron('xtrabackup-weekly')
121+
end
122+
123+
it 'contains the daily cronjob with all weekdays' do
124+
is_expected.to contain_cron('xtrabackup-daily').with(
125+
ensure: 'present',
126+
command: '/usr/local/sbin/xtrabackup.sh --target-dir=/tmp --backup',
127+
user: 'root',
128+
hour: '23',
129+
minute: '5',
130+
weekday: '*',
131+
)
132+
end
133+
end
134+
135+
context 'with prescript defined' do
136+
let(:params) do
137+
{ prescript: ['rsync -a /tmp backup01.local-lan:',
138+
'rsync -a /tmp backup02.local-lan:'] }.merge(default_params)
139+
end
140+
141+
it 'contains the prescript' do
142+
is_expected.to contain_file('xtrabackup.sh').with_content(
143+
%r{.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*},
144+
)
145+
end
146+
end
147+
148+
context 'with postscript defined' do
149+
let(:params) do
150+
{ postscript: ['rsync -a /tmp backup01.local-lan:',
151+
'rsync -a /tmp backup02.local-lan:'] }.merge(default_params)
152+
end
153+
154+
it 'contains the prostscript' do
155+
is_expected.to contain_file('xtrabackup.sh').with_content(
156+
%r{.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*},
157+
)
158+
end
159+
end
160+
161+
context 'with mariabackup' do
162+
let(:params) do
163+
{ backupmethod: 'mariabackup' }.merge(default_params)
164+
end
165+
166+
it 'contain the mariabackup executor' do
167+
is_expected.to contain_file('xtrabackup.sh').with_content(
168+
%r{(\n*^mariabackup\s+.*\$@)},
169+
)
170+
end
171+
end
172+
end
173+
end
174+
# rubocop:enable RSpec/NestedGroups
175+
end

spec/classes/mysql_server_backup_spec.rb

-56
Original file line numberDiff line numberDiff line change
@@ -355,62 +355,6 @@ class { 'mysql::server': }
355355
)
356356
end
357357
end
358-
359-
context 'with the xtrabackup provider' do
360-
let(:params) do
361-
default_params.merge(provider: 'xtrabackup')
362-
end
363-
364-
it 'contains the wrapper script' do
365-
is_expected.to contain_file('xtrabackup.sh').with_content(
366-
%r{(\n*^xtrabackup\s+.*\$@)},
367-
)
368-
end
369-
370-
context 'with prescript defined' do
371-
let(:params) do
372-
default_params.merge(provider: 'xtrabackup',
373-
prescript: [
374-
'rsync -a /tmp backup01.local-lan:',
375-
'rsync -a /tmp backup02.local-lan:',
376-
])
377-
end
378-
379-
it 'contains the prescript' do
380-
is_expected.to contain_file('xtrabackup.sh').with_content(
381-
%r{.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*},
382-
)
383-
end
384-
end
385-
386-
context 'with postscript defined' do
387-
let(:params) do
388-
default_params.merge(provider: 'xtrabackup',
389-
postscript: [
390-
'rsync -a /tmp backup01.local-lan:',
391-
'rsync -a /tmp backup02.local-lan:',
392-
])
393-
end
394-
395-
it 'contains the prostscript' do
396-
is_expected.to contain_file('xtrabackup.sh').with_content(
397-
%r{.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*},
398-
)
399-
end
400-
end
401-
context 'with mariabackup' do
402-
let(:params) do
403-
default_params.merge(provider: 'xtrabackup',
404-
backupmethod: 'mariabackup')
405-
end
406-
407-
it 'contain the mariabackup executor' do
408-
is_expected.to contain_file('xtrabackup.sh').with_content(
409-
%r{(\n*^mariabackup\s+.*\$@)},
410-
)
411-
end
412-
end
413-
end
414358
end
415359
end
416360
# rubocop:enable RSpec/NestedGroups

0 commit comments

Comments
 (0)