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

Support compression command and extension #1363

Merged
merged 4 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions manifests/backup/mysqlbackup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
$optional_args = [],
$incremental_backups = false,
$install_cron = true,
$compression_command = undef,
$compression_extension = undef,
) inherits mysql::params {
mysql_user { "${backupuser}@localhost":
ensure => $ensure,
Expand Down
4 changes: 3 additions & 1 deletion manifests/backup/mysqldump.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
$mysqlbackupdir_target = undef,
$incremental_backups = false,
$install_cron = true,
$compression_command = 'bzcat -zc',
$compression_extension = '.bz2'
) inherits mysql::params {
unless $::osfamily == 'FreeBSD' {
if $backupcompress {
if $backupcompress and $compression_command == 'bzcat -zc' {
ensure_packages(['bzip2'])
Package['bzip2'] -> File['mysqlbackup.sh']
}
Expand Down
2 changes: 2 additions & 0 deletions manifests/backup/xtrabackup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
$additional_cron_args = '--backup',
$incremental_backups = true,
$install_cron = true,
$compression_command = undef,
$compression_extension = undef,
) inherits mysql::params {
ensure_packages($xtrabackup_package_name)

Expand Down
8 changes: 8 additions & 0 deletions manifests/server/backup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
# Specifies an array of optional arguments which should be passed through to the backup tool. (Supported by the xtrabackup and mysqldump providers.)
# @param install_cron
# Manage installation of cron package
# @param compression_command
# Configure the command used to compress the backup (when using the mysqldump provider)
# @param compression_extension
# Configure the file extension for the compressed backup (when using the mysqldump provider)
class mysql::server::backup (
$backupuser = undef,
$backuppassword = undef,
Expand Down Expand Up @@ -94,6 +98,8 @@
$optional_args = [],
$incremental_backups = true,
$install_cron = true,
$compression_command = undef,
$compression_extension = undef
) inherits mysql::params {
if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
warning(translate("The 'prescript' option is not currently implemented for the %{provider} backup provider.",
Expand Down Expand Up @@ -127,6 +133,8 @@
'optional_args' => $optional_args,
'incremental_backups' => $incremental_backups,
'install_cron' => $install_cron,
'compression_command' => $compression_command,
'compression_extension' => $compression_extension,
}
})
}
19 changes: 19 additions & 0 deletions spec/classes/mysql_backup_mysqldump_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ class { 'mysql::server': }
)
}
end

context 'with compression_command' do
let(:params) do
{
compression_command: 'TEST -TEST',
compression_extension: '.TEST'
}.merge(default_params)
end

it {
is_expected.to contain_file('mysqlbackup.sh').with_content(
%r{(\| TEST -TEST)},
)
is_expected.to contain_file('mysqlbackup.sh').with_content(
%r{(\.TEST)},
)
is_expected.not_to contain_package('bzip2')
}
end
end
end
# rubocop:enable RSpec/NestedGroups
Expand Down
6 changes: 3 additions & 3 deletions templates/mysqlbackup.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read d
do
<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
${ADDITIONAL_OPTIONS} \
${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
${dbname} <% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %>
done
<% else -%>
<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
${ADDITIONAL_OPTIONS} \
--all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
--all-databases <% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %>
<% end -%>
<% else -%>
<% @backupdatabases.each do |db| -%>
<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
${ADDITIONAL_OPTIONS} \
<%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
<%= db %><% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %>
<% end -%>
<% end -%>

Expand Down