Skip to content

Mysql::backup Compression Optional #117

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

Merged
merged 3 commits into from
Oct 13, 2012
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
3 changes: 3 additions & 0 deletions manifests/backup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -19,12 +20,14 @@
# backupuser => 'myuser',
# backuppassword => 'mypassword',
# backupdir => '/tmp/backups',
# backupcompress => true,
# }
#
class mysql::backup (
$backupuser,
$backuppassword,
$backupdir,
$backupcompress = true,
$ensure = 'present'
) {

Expand Down
71 changes: 48 additions & 23 deletions spec/classes/mysql_backup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,57 @@

describe 'mysql::backup' do

let(:params) {
let(:default_params) {
{ 'backupuser' => 'testuser',
'backuppassword' => 'testpass',
'backupdir' => '/tmp',
}
}

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_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'
)}

context "standard conditions" do
let(:params) { default_params }

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_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', [
' --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
2 changes: 1 addition & 1 deletion templates/mysqlbackup.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>