Skip to content

Commit 6759529

Browse files
committed
Support compression command and extension
This makes it possible to configure the previously hardcoded bzip2 compression and use a faster or parallel compression. It doesn't support package installation for other compression commands.
1 parent 28bddab commit 6759529

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

manifests/backup/mysqldump.pp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
$mysqlbackupdir_target = undef,
3131
$incremental_backups = false,
3232
$install_cron = true,
33+
$compression_command = 'bzcat -zc',
34+
$compression_extension = '.bz2'
3335
) inherits mysql::params {
3436
unless $::osfamily == 'FreeBSD' {
35-
if $backupcompress {
37+
if $backupcompress and $compression_command == 'bzcat -zc' {
3638
ensure_packages(['bzip2'])
3739
Package['bzip2'] -> File['mysqlbackup.sh']
3840
}

manifests/server/backup.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
# Specifies an array of optional arguments which should be passed through to the backup tool. (Supported by the xtrabackup and mysqldump providers.)
6868
# @param install_cron
6969
# Manage installation of cron package
70+
# @param compression_command
71+
# Configure the command used to compress the backup (when using the mysqldump provider)
72+
# @param compression_extension
73+
# Configure the file extension for the compressed backup (when using the mysqldump provider)
7074
class mysql::server::backup (
7175
$backupuser = undef,
7276
$backuppassword = undef,
@@ -94,6 +98,8 @@
9498
$optional_args = [],
9599
$incremental_backups = true,
96100
$install_cron = true,
101+
$compression_command = undef,
102+
$compression_extension = undef
97103
) inherits mysql::params {
98104
if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
99105
warning(translate("The 'prescript' option is not currently implemented for the %{provider} backup provider.",
@@ -127,6 +133,8 @@
127133
'optional_args' => $optional_args,
128134
'incremental_backups' => $incremental_backups,
129135
'install_cron' => $install_cron,
136+
'compression_command' => $compression_command,
137+
'compression_extension' => $compression_extension,
130138
}
131139
})
132140
}

spec/classes/mysql_backup_mysqldump_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ class { 'mysql::server': }
5252
)
5353
}
5454
end
55+
56+
context 'with compression_command' do
57+
let(:params) do
58+
{
59+
compression_command: "TEST -TEST",
60+
compression_extension: ".TEST"
61+
}.merge(default_params)
62+
end
63+
it {
64+
is_expected.to contain_file('mysqlbackup.sh').with_content(
65+
%r{(\| TEST -TEST)},
66+
)
67+
is_expected.to contain_file('mysqlbackup.sh').with_content(
68+
%r{(\.TEST)},
69+
)
70+
is_expected.to_not contain_package('bzip2')
71+
}
72+
end
5573
end
5674
end
5775
# rubocop:enable RSpec/NestedGroups

templates/mysqlbackup.sh.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read d
9393
do
9494
<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
9595
${ADDITIONAL_OPTIONS} \
96-
${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
96+
${dbname} <% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %>
9797
done
9898
<% else -%>
9999
<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
100100
${ADDITIONAL_OPTIONS} \
101-
--all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
101+
--all-databases <% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %>
102102
<% end -%>
103103
<% else -%>
104104
<% @backupdatabases.each do |db| -%>
105105
<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
106106
${ADDITIONAL_OPTIONS} \
107-
<%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
107+
<%= db %><% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %>
108108
<% end -%>
109109
<% end -%>
110110

0 commit comments

Comments
 (0)