Merge pull request #117 from hunner/optional_compression
Mysql::backup Compression Optional
This commit is contained in:
commit
bb4f15b8fe
3 changed files with 46 additions and 18 deletions
|
@ -6,6 +6,7 @@
|
|||
# [*backupuser*] - The name of the mysql backup user.
|
||||
# [*backuppassword*] - The password of the mysql backup user.
|
||||
# [*backupdir*] - The target directory of the mysqldump.
|
||||
# [*backupcompress*] - Boolean to compress backup with bzip2.
|
||||
#
|
||||
# Actions:
|
||||
# GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost'
|
||||
|
@ -19,12 +20,14 @@
|
|||
# backupuser => 'myuser',
|
||||
# backuppassword => 'mypassword',
|
||||
# backupdir => '/tmp/backups',
|
||||
# backupcompress => true,
|
||||
# }
|
||||
#
|
||||
class mysql::backup (
|
||||
$backupuser,
|
||||
$backuppassword,
|
||||
$backupdir,
|
||||
$backupcompress = true,
|
||||
$ensure = 'present'
|
||||
) {
|
||||
|
||||
|
|
|
@ -2,32 +2,57 @@ require 'spec_helper'
|
|||
|
||||
describe 'mysql::backup' do
|
||||
|
||||
let(:params) {
|
||||
let(:default_params) {
|
||||
{ 'backupuser' => 'testuser',
|
||||
'backuppassword' => 'testpass',
|
||||
'backupdir' => '/tmp',
|
||||
}
|
||||
}
|
||||
context "standard conditions" do
|
||||
let(:params) { default_params }
|
||||
|
||||
it { should contain_database_user('testuser@localhost')}
|
||||
it { should contain_database_user('testuser@localhost')}
|
||||
|
||||
it { should contain_database_grant('testuser@localhost').with(
|
||||
:privileges => [ 'Select_priv', 'Reload_priv', 'Lock_tables_priv', 'Show_view_priv' ]
|
||||
)}
|
||||
it { should contain_database_grant('testuser@localhost').with(
|
||||
:privileges => [ 'Select_priv', 'Reload_priv', 'Lock_tables_priv', 'Show_view_priv' ]
|
||||
)}
|
||||
|
||||
it { should contain_cron('mysql-backup').with(
|
||||
:command => '/usr/local/sbin/mysqlbackup.sh',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
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('mysqlbackup.sh').with(
|
||||
:path => '/usr/local/sbin/mysqlbackup.sh',
|
||||
:ensure => 'present'
|
||||
) }
|
||||
|
||||
it { should contain_file('mysqlbackupdir').with(
|
||||
:path => '/tmp',
|
||||
:ensure => 'directory'
|
||||
)}
|
||||
it { should contain_file('mysqlbackupdir').with(
|
||||
:path => '/tmp',
|
||||
:ensure => 'directory'
|
||||
)}
|
||||
|
||||
it 'should have compression by default' do
|
||||
verify_contents(subject, 'mysqlbackup.sh', [
|
||||
' --all-databases | bzcat -zc > ${DIR}/mysql_backup_`date +%Y%m%d-%H%M%S`.sql.bz2',
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
context "with compression disabled" do
|
||||
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', [
|
||||
' --all-databases > ${DIR}/mysql_backup_`date +%Y%m%d-%H%M%S`.sql',
|
||||
])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,5 +19,5 @@ PATH=/usr/bin:/usr/sbin:/bin:/sbin
|
|||
|
||||
find $DIR -mtime +30 -exec rm -f {} \;
|
||||
mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \
|
||||
--all-databases | bzcat -zc > ${DIR}/mysql_backup_`date +%Y%m%d-%H%M%S`.sql.bz2
|
||||
--all-databases <% if backupcompress %>| bzcat -zc <% end %>> ${DIR}/mysql_backup_`date +%Y%m%d-%H%M%S`.sql<% if backupcompress %>.bz2<% end %>
|
||||
|
||||
|
|
Loading…
Reference in a new issue