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

Make backup success file path configurable #1207

Merged
merged 6 commits into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 23 additions & 22 deletions manifests/backup/mysqlbackup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@
# @api private
#
class mysql::backup::mysqlbackup (
$backupuser = '',
$backuppassword = '',
$maxallowedpacket = '1M',
$backupdir = '',
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = $mysql::params::root_group,
$backupcompress = true,
$backuprotate = 30,
$backupmethod = '',
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$include_triggers = true,
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$optional_args = [],
$backupuser = '',
$backuppassword = '',
$maxallowedpacket = '1M',
$backupdir = '',
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = $mysql::params::root_group,
$backupcompress = true,
$backuprotate = 30,
$backupmethod = '',
$backup_success_file_path = undef,
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$include_triggers = true,
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$optional_args = [],
) inherits mysql::params {

mysql_user { "${backupuser}@localhost":
Expand Down
49 changes: 25 additions & 24 deletions manifests/backup/mysqldump.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@
# @api private
#
class mysql::backup::mysqldump (
$backupuser = '',
$backuppassword = '',
$backupdir = '',
$maxallowedpacket = '1M',
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = $mysql::params::root_group,
$backupcompress = true,
$backuprotate = 30,
$backupmethod = 'mysqldump',
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$include_triggers = false,
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$optional_args = [],
$mysqlbackupdir_ensure = 'directory',
$mysqlbackupdir_target = undef,
$backupuser = '',
$backuppassword = '',
$backupdir = '',
$maxallowedpacket = '1M',
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = $mysql::params::root_group,
$backupcompress = true,
$backuprotate = 30,
$backupmethod = 'mysqldump',
$backup_success_file_path = undef,
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$include_triggers = false,
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$optional_args = [],
$mysqlbackupdir_ensure = 'directory',
$mysqlbackupdir_target = undef,
) inherits mysql::params {

if $backupcompress {
Expand Down
100 changes: 51 additions & 49 deletions manifests/server/backup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
# @param backupcompress
# Whether or not to compress the backup (when using the mysqldump provider)
# @param backupmethod
# The execution binary for backing up. ex. mysqldump, xtrabackup, mariabackup
# The execution binary for backing up. ex. mysqldump, xtrabackup, mariabackup
# @param backup_success_file_path
# Specify a path where upon successfull backup a file should be created for checking purposes.
# @param backuprotate
# Backup rotation interval in 24 hour periods.
# @param ignore_events
Expand All @@ -56,36 +58,36 @@
# @param execpath
# Allows you to set a custom PATH should your MySQL installation be non-standard places. Defaults to `/usr/bin:/usr/sbin:/bin:/sbin`.
# @param provider
# Sets the server backup implementation. Valid values are:
# Sets the server backup implementation. Valid values are:
# @param maxallowedpacket
# Defines the maximum SQL statement size for the backup dump script. The default value is 1MB, as this is the default MySQL Server value.
# @param optional_args
# Specifies an array of optional arguments which should be passed through to the backup tool. (Supported by the xtrabackup and mysqldump providers.)
#
class mysql::server::backup (
$backupuser = undef,
$backuppassword = undef,
$backupdir = undef,
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = 'root',
$backupcompress = true,
$backuprotate = 30,
$backupmethod = undef,
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$include_routines = false,
$include_triggers = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$provider = 'mysqldump',
$maxallowedpacket = '1M',
$optional_args = [],
$backupuser = undef,
$backuppassword = undef,
$backupdir = undef,
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = 'root',
$backupcompress = true,
$backuprotate = 30,
$backupmethod = undef,
$backup_success_file_path = '/tmp/mysqlbackup_success',
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$include_routines = false,
$include_triggers = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$provider = 'mysqldump',
$maxallowedpacket = '1M',
$optional_args = [],
) {

if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
Expand All @@ -95,29 +97,29 @@

create_resources('class', {
"mysql::backup::${provider}" => {
'backupuser' => $backupuser,
'backuppassword' => $backuppassword,
'backupdir' => $backupdir,
'backupdirmode' => $backupdirmode,
'backupdirowner' => $backupdirowner,
'backupdirgroup' => $backupdirgroup,
'backupcompress' => $backupcompress,
'backuprotate' => $backuprotate,
'backupmethod' => $backupmethod,
'ignore_events' => $ignore_events,
'delete_before_dump' => $delete_before_dump,
'backupdatabases' => $backupdatabases,
'file_per_database' => $file_per_database,
'include_routines' => $include_routines,
'include_triggers' => $include_triggers,
'ensure' => $ensure,
'time' => $time,
'prescript' => $prescript,
'postscript' => $postscript,
'execpath' => $execpath,
'maxallowedpacket' => $maxallowedpacket,
'optional_args' => $optional_args,
'backupuser' => $backupuser,
'backuppassword' => $backuppassword,
'backupdir' => $backupdir,
'backupdirmode' => $backupdirmode,
'backupdirowner' => $backupdirowner,
'backupdirgroup' => $backupdirgroup,
'backupcompress' => $backupcompress,
'backuprotate' => $backuprotate,
'backupmethod' => $backupmethod,
'backup_success_file_path' => $backup_success_file_path,
'ignore_events' => $ignore_events,
'delete_before_dump' => $delete_before_dump,
'backupdatabases' => $backupdatabases,
'file_per_database' => $file_per_database,
'include_routines' => $include_routines,
'include_triggers' => $include_triggers,
'ensure' => $ensure,
'time' => $time,
'prescript' => $prescript,
'postscript' => $postscript,
'execpath' => $execpath,
'maxallowedpacket' => $maxallowedpacket,
'optional_args' => $optional_args,
}
})

}
27 changes: 27 additions & 0 deletions spec/classes/mysql_server_backup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,33 @@ class { 'mysql::server': }
end
end

context 'with delete after dump' do
let(:custom_params) do
{
'delete_before_dump' => false,
}
end
let(:params) do
default_params.merge!(custom_params)
end

it { is_expected.to contain_file('mysqlbackup.sh').with_content(%r{touch /tmp/mysqlbackup_success}) }
end

context 'with delete after dump and custom success file path' do
let(:custom_params) do
{
'delete_before_dump' => false,
'backup_success_file_path' => '/opt/mysqlbackup_success',
}
end
let(:params) do
default_params.merge!(custom_params)
end

it { is_expected.to contain_file('mysqlbackup.sh').with_content(%r{touch /opt/mysqlbackup_success}) }
end

context 'custom ownership and mode for backupdir' do
let(:params) do
{ backupdirmode: '0750',
Expand Down
2 changes: 1 addition & 1 deletion templates/mysqlbackup.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ done
<% unless @delete_before_dump -%>
if [ $? -eq 0 ] ; then
cleanup
touch /tmp/mysqlbackup_success
touch <%= @backup_success_file_path %>
fi
<% end -%>

Expand Down
2 changes: 1 addition & 1 deletion templates/xtrabackup.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ cleanup
<% unless @delete_before_dump -%>
if [ $? -eq 0 ] ; then
cleanup
touch /tmp/mysqlbackup_success
touch <%= @backup_success_file_path %>
fi
<% end -%>

Expand Down