Skip to content

Commit 99ecc8c

Browse files
committed
fix handling of incremental backups with xtrabackup
1 parent 4f0ea63 commit 99ecc8c

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

manifests/backup/xtrabackup.pp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,18 @@
5151
}
5252

5353
if $incremental_backups {
54+
# Warn if old backups are removed too soon. Incremental backups will fail
55+
# if the full backup is no longer available.
56+
if ($backuprotate.convert_to(Integer) < 7) {
57+
warning(translate('The value for `backuprotate` is too low, it must be set to at least 7 days when using incremental backups.'))
58+
}
59+
60+
# The --target-dir uses a more predictable value for the full backup so
61+
# that it can easily be calculated and used in incremental backup jobs.
62+
# Besides that it allows to have multiple full backups.
5463
cron { 'xtrabackup-weekly':
5564
ensure => $ensure,
56-
command => "/usr/local/sbin/xtrabackup.sh --target-dir=${backupdir} ${additional_cron_args}",
65+
command => "/usr/local/sbin/xtrabackup.sh --target-dir=${backupdir}/$(date +\\%F)_full ${additional_cron_args}",
5766
user => 'root',
5867
hour => $time[0],
5968
minute => $time[1],
@@ -62,9 +71,19 @@
6271
}
6372
}
6473

74+
# Wether to use GNU or BSD date format.
75+
case $::osfamily {
76+
'FreeBSD','OpenBSD': {
77+
$dateformat = '$(date -v-sun +\\%F)_full'
78+
}
79+
default: {
80+
$dateformat = '$(date -d "last sunday" +\\%F)_full'
81+
}
82+
}
83+
6584
$daily_cron_data = ($incremental_backups) ? {
6685
true => {
67-
'directories' => "--incremental-basedir=${backupdir} --target-dir=${backupdir}/$(date +\\%F_\\%H-\\%M-\\%S)",
86+
'directories' => "--incremental-basedir=${backupdir}/${dateformat} --target-dir=${backupdir}/$(date +\\%F_\\%H-\\%M-\\%S)",
6887
'weekday' => '1-6',
6988
},
7089
false => {

spec/classes/mysql_backup_xtrabackup_spec.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class { 'mysql::server': }
3131
is_expected.to contain_cron('xtrabackup-weekly')
3232
.with(
3333
ensure: 'present',
34-
command: '/usr/local/sbin/xtrabackup.sh --target-dir=/tmp/$(date +\%F_\%H-\%M-\%S) --backup',
34+
command: '/usr/local/sbin/xtrabackup.sh --target-dir=/tmp/$(date +\%F)_full --backup',
3535
user: 'root',
3636
hour: '23',
3737
minute: '5',
@@ -41,10 +41,16 @@ class { 'mysql::server': }
4141
end
4242

4343
it 'contains the daily cronjob for weekdays 1-6' do
44+
dateformat = case facts[:osfamily]
45+
when 'FreeBSD', 'OpenBSD'
46+
'$(date -v-sun +\%F)_full'
47+
else
48+
'$(date -d "last sunday" +\%F)_full'
49+
end
4450
is_expected.to contain_cron('xtrabackup-daily')
4551
.with(
4652
ensure: 'present',
47-
command: '/usr/local/sbin/xtrabackup.sh --incremental-basedir=/tmp --target-dir=/tmp/$(date +\%F_\%H-\%M-\%S) --backup',
53+
command: "/usr/local/sbin/xtrabackup.sh --incremental-basedir=/tmp/#{dateformat} --target-dir=/tmp/$(date +\\\%F_\\\%H-\\\%M-\\\%S) --backup",
4854
user: 'root',
4955
hour: '23',
5056
minute: '5',
@@ -84,11 +90,18 @@ class { 'mysql::server': }
8490
{ additional_cron_args: '--backup --skip-ssl' }.merge(default_params)
8591
end
8692

93+
dateformat = case facts[:osfamily]
94+
when 'FreeBSD', 'OpenBSD'
95+
'$(date -v-sun +\%F)_full'
96+
else
97+
'$(date -d "last sunday" +\%F)_full'
98+
end
99+
87100
it 'contains the weekly cronjob' do
88101
is_expected.to contain_cron('xtrabackup-weekly')
89102
.with(
90103
ensure: 'present',
91-
command: '/usr/local/sbin/xtrabackup.sh --target-dir=/tmp/$(date +\%F_\%H-\%M-\%S) --backup --skip-ssl',
104+
command: '/usr/local/sbin/xtrabackup.sh --target-dir=/tmp/$(date +\%F)_full --backup --skip-ssl',
92105
user: 'root',
93106
hour: '23',
94107
minute: '5',
@@ -101,7 +114,7 @@ class { 'mysql::server': }
101114
is_expected.to contain_cron('xtrabackup-daily')
102115
.with(
103116
ensure: 'present',
104-
command: '/usr/local/sbin/xtrabackup.sh --incremental-basedir=/tmp --target-dir=/tmp/$(date +\%F_\%H-\%M-\%S) --backup --skip-ssl',
117+
command: "/usr/local/sbin/xtrabackup.sh --incremental-basedir=/tmp/#{dateformat} --target-dir=/tmp/$(date +\\\%F_\\\%H-\\\%M-\\\%S) --backup --skip-ssl",
105118
user: 'root',
106119
hour: '23',
107120
minute: '5',

0 commit comments

Comments
 (0)