Skip to content

Commit f0933c0

Browse files
authored
Merge pull request #1363 from dodevops/feature/compressutility
Support compression command and extension
2 parents 69772a4 + 3b0bdf7 commit f0933c0

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed

manifests/backup/mysqlbackup.pp

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
$optional_args = [],
3030
$incremental_backups = false,
3131
$install_cron = true,
32+
$compression_command = undef,
33+
$compression_extension = undef,
3234
) inherits mysql::params {
3335
mysql_user { "${backupuser}@localhost":
3436
ensure => $ensure,

manifests/backup/mysqldump.pp

+3-1
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/backup/xtrabackup.pp

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
$additional_cron_args = '--backup',
3232
$incremental_backups = true,
3333
$install_cron = true,
34+
$compression_command = undef,
35+
$compression_extension = undef,
3436
) inherits mysql::params {
3537
ensure_packages($xtrabackup_package_name)
3638

manifests/server/backup.pp

+9
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
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). Make sure the command exists
72+
# on the target system. Packages for it are NOT automatically installed.
73+
# @param compression_extension
74+
# Configure the file extension for the compressed backup (when using the mysqldump provider)
7075
class mysql::server::backup (
7176
$backupuser = undef,
7277
$backuppassword = undef,
@@ -94,6 +99,8 @@
9499
$optional_args = [],
95100
$incremental_backups = true,
96101
$install_cron = true,
102+
$compression_command = undef,
103+
$compression_extension = undef
97104
) inherits mysql::params {
98105
if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
99106
warning(translate("The 'prescript' option is not currently implemented for the %{provider} backup provider.",
@@ -127,6 +134,8 @@
127134
'optional_args' => $optional_args,
128135
'incremental_backups' => $incremental_backups,
129136
'install_cron' => $install_cron,
137+
'compression_command' => $compression_command,
138+
'compression_extension' => $compression_extension,
130139
}
131140
})
132141
}

spec/classes/mysql_backup_mysqldump_spec.rb

+19
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ 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+
64+
it {
65+
is_expected.to contain_file('mysqlbackup.sh').with_content(
66+
%r{(\| TEST -TEST)},
67+
)
68+
is_expected.to contain_file('mysqlbackup.sh').with_content(
69+
%r{(\.TEST)},
70+
)
71+
is_expected.not_to contain_package('bzip2')
72+
}
73+
end
5574
end
5675
end
5776
# rubocop:enable RSpec/NestedGroups

templates/mysqlbackup.sh.erb

+3-3
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)