diff --git a/manifests/backup/mysqlbackup.pp b/manifests/backup/mysqlbackup.pp index 3cd4e150b..ab0bd17a5 100644 --- a/manifests/backup/mysqlbackup.pp +++ b/manifests/backup/mysqlbackup.pp @@ -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": diff --git a/manifests/backup/mysqldump.pp b/manifests/backup/mysqldump.pp index d76545d64..7c95f91d6 100644 --- a/manifests/backup/mysqldump.pp +++ b/manifests/backup/mysqldump.pp @@ -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 { diff --git a/manifests/server/backup.pp b/manifests/server/backup.pp index 7e6e32513..0b462b986 100644 --- a/manifests/server/backup.pp +++ b/manifests/server/backup.pp @@ -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 @@ -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)/ { @@ -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, } }) - } diff --git a/spec/classes/mysql_server_backup_spec.rb b/spec/classes/mysql_server_backup_spec.rb index b7ff1d6c0..02c9fa94b 100644 --- a/spec/classes/mysql_server_backup_spec.rb +++ b/spec/classes/mysql_server_backup_spec.rb @@ -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', diff --git a/templates/mysqlbackup.sh.erb b/templates/mysqlbackup.sh.erb index 77a437f2b..19706fb27 100755 --- a/templates/mysqlbackup.sh.erb +++ b/templates/mysqlbackup.sh.erb @@ -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 -%> diff --git a/templates/xtrabackup.sh.erb b/templates/xtrabackup.sh.erb index de5319763..bc01ba9e4 100644 --- a/templates/xtrabackup.sh.erb +++ b/templates/xtrabackup.sh.erb @@ -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 -%>