2012-04-24 07:53:59 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2013-09-13 19:13:59 +02:00
|
|
|
describe 'mysql::server::backup' do
|
2012-04-24 07:53:59 +02:00
|
|
|
|
2012-09-26 22:40:20 +02:00
|
|
|
let(:default_params) {
|
2013-07-05 18:32:19 +02:00
|
|
|
{ 'backupuser' => 'testuser',
|
|
|
|
'backuppassword' => 'testpass',
|
|
|
|
'backupdir' => '/tmp',
|
|
|
|
'backuprotate' => '25',
|
|
|
|
'delete_before_dump' => true,
|
2012-04-24 07:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
2013-07-10 05:11:11 +02:00
|
|
|
context 'standard conditions' do
|
2012-09-26 22:40:20 +02:00
|
|
|
let(:params) { default_params }
|
|
|
|
|
2013-12-18 13:35:20 +01:00
|
|
|
it { should contain_mysql_user('testuser@localhost').with(
|
|
|
|
:require => 'Class[Mysql::Server::Root_password]'
|
|
|
|
)}
|
2012-09-26 22:40:20 +02:00
|
|
|
|
2013-08-29 00:03:51 +02:00
|
|
|
it { should contain_mysql_grant('testuser@localhost/*.*').with(
|
|
|
|
:privileges => ["SELECT", "RELOAD", "LOCK TABLES", "SHOW VIEW"]
|
2012-09-26 22:40:20 +02:00
|
|
|
)}
|
|
|
|
|
|
|
|
it { should contain_cron('mysql-backup').with(
|
|
|
|
:command => '/usr/local/sbin/mysqlbackup.sh',
|
|
|
|
:ensure => 'present'
|
|
|
|
)}
|
|
|
|
|
|
|
|
it { should contain_file('mysqlbackup.sh').with(
|
|
|
|
:path => '/usr/local/sbin/mysqlbackup.sh',
|
|
|
|
:ensure => 'present'
|
|
|
|
) }
|
|
|
|
|
|
|
|
it { should contain_file('mysqlbackupdir').with(
|
|
|
|
:path => '/tmp',
|
|
|
|
:ensure => 'directory'
|
|
|
|
)}
|
|
|
|
|
|
|
|
it 'should have compression by default' do
|
|
|
|
verify_contents(subject, 'mysqlbackup.sh', [
|
2013-04-23 14:18:23 +02:00
|
|
|
' --all-databases | bzcat -zc > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql.bz2',
|
2012-09-26 22:40:20 +02:00
|
|
|
])
|
|
|
|
end
|
2013-07-05 18:32:19 +02:00
|
|
|
|
|
|
|
it 'should have 25 days of rotation' do
|
|
|
|
# MySQL counts from 0 I guess.
|
|
|
|
should contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/)
|
|
|
|
end
|
2012-09-26 22:40:20 +02:00
|
|
|
end
|
|
|
|
|
2013-11-13 19:33:13 +01:00
|
|
|
context 'custom ownership and mode for backupdir' do
|
|
|
|
let(:params) do
|
|
|
|
{ :backupdirmode => '0750',
|
|
|
|
:backupdirowner => 'testuser',
|
|
|
|
:backupdirgroup => 'testgrp',
|
|
|
|
}.merge(default_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should contain_file('mysqlbackupdir').with(
|
|
|
|
:path => '/tmp',
|
|
|
|
:ensure => 'directory',
|
|
|
|
:mode => '0750',
|
|
|
|
:owner => 'testuser',
|
|
|
|
:group => 'testgrp'
|
|
|
|
) }
|
|
|
|
end
|
|
|
|
|
2013-07-10 05:11:11 +02:00
|
|
|
context 'with compression disabled' do
|
2012-09-26 22:40:20 +02:00
|
|
|
let(:params) do
|
|
|
|
{ :backupcompress => false }.merge(default_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should contain_file('mysqlbackup.sh').with(
|
|
|
|
:path => '/usr/local/sbin/mysqlbackup.sh',
|
|
|
|
:ensure => 'present'
|
|
|
|
) }
|
|
|
|
|
|
|
|
it 'should be able to disable compression' do
|
|
|
|
verify_contents(subject, 'mysqlbackup.sh', [
|
2013-04-23 14:18:23 +02:00
|
|
|
' --all-databases > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql',
|
2012-09-26 22:40:20 +02:00
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
2013-08-13 23:44:41 +02:00
|
|
|
|
|
|
|
context 'with database list specified' do
|
|
|
|
let(:params) do
|
|
|
|
{ :backupdatabases => ['mysql'] }.merge(default_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should contain_file('mysqlbackup.sh').with(
|
|
|
|
:path => '/usr/local/sbin/mysqlbackup.sh',
|
|
|
|
:ensure => 'present'
|
|
|
|
) }
|
|
|
|
|
|
|
|
it 'should have a backup file for each database' do
|
2013-10-15 23:16:40 +02:00
|
|
|
content = subject.resource('file','mysqlbackup.sh').send(:parameters)[:content]
|
2013-08-13 23:44:41 +02:00
|
|
|
content.should match(' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date')
|
|
|
|
# verify_contents(subject, 'mysqlbackup.sh', [
|
|
|
|
# ' mysql | bzcat -zc ${DIR}/${PREFIX}mysql_`date +%Y%m%d-%H%M%S`.sql',
|
|
|
|
# ])
|
|
|
|
end
|
|
|
|
end
|
2013-08-27 22:15:29 +02:00
|
|
|
|
|
|
|
context 'with file per database' do
|
|
|
|
let(:params) do
|
|
|
|
default_params.merge({ :file_per_database => true })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should loop through backup all databases' do
|
|
|
|
verify_contents(subject, 'mysqlbackup.sh', [
|
|
|
|
'mysql -s -r -N -e \'SHOW DATABASES\' | while read dbname',
|
|
|
|
'do',
|
|
|
|
' mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \\',
|
|
|
|
' ${dbname} | bzcat -zc > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql.bz2',
|
|
|
|
'done',
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with compression disabled' do
|
|
|
|
let(:params) do
|
|
|
|
default_params.merge({ :file_per_database => true, :backupcompress => false })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should loop through backup all databases without compression' do
|
|
|
|
verify_contents(subject, 'mysqlbackup.sh', [
|
|
|
|
' ${dbname} > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql',
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-04-24 07:53:59 +02:00
|
|
|
end
|