Skip to content

Commit bb4f15b

Browse files
author
Ryan Coleman
committed
Merge pull request #117 from hunner/optional_compression
Mysql::backup Compression Optional
2 parents 837e839 + d212c87 commit bb4f15b

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

manifests/backup.pp

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# [*backupuser*] - The name of the mysql backup user.
77
# [*backuppassword*] - The password of the mysql backup user.
88
# [*backupdir*] - The target directory of the mysqldump.
9+
# [*backupcompress*] - Boolean to compress backup with bzip2.
910
#
1011
# Actions:
1112
# GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost'
@@ -19,12 +20,14 @@
1920
# backupuser => 'myuser',
2021
# backuppassword => 'mypassword',
2122
# backupdir => '/tmp/backups',
23+
# backupcompress => true,
2224
# }
2325
#
2426
class mysql::backup (
2527
$backupuser,
2628
$backuppassword,
2729
$backupdir,
30+
$backupcompress = true,
2831
$ensure = 'present'
2932
) {
3033

spec/classes/mysql_backup_spec.rb

+48-23
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,57 @@
22

33
describe 'mysql::backup' do
44

5-
let(:params) {
5+
let(:default_params) {
66
{ 'backupuser' => 'testuser',
77
'backuppassword' => 'testpass',
88
'backupdir' => '/tmp',
99
}
1010
}
11-
12-
it { should contain_database_user('testuser@localhost')}
13-
14-
it { should contain_database_grant('testuser@localhost').with(
15-
:privileges => [ 'Select_priv', 'Reload_priv', 'Lock_tables_priv', 'Show_view_priv' ]
16-
)}
17-
18-
it { should contain_cron('mysql-backup').with(
19-
:command => '/usr/local/sbin/mysqlbackup.sh',
20-
:ensure => 'present'
21-
)}
22-
23-
it { should contain_file('mysqlbackup.sh').with(
24-
:path => '/usr/local/sbin/mysqlbackup.sh',
25-
:ensure => 'present'
26-
)}
27-
28-
it { should contain_file('mysqlbackupdir').with(
29-
:path => '/tmp',
30-
:ensure => 'directory'
31-
)}
32-
11+
context "standard conditions" do
12+
let(:params) { default_params }
13+
14+
it { should contain_database_user('testuser@localhost')}
15+
16+
it { should contain_database_grant('testuser@localhost').with(
17+
:privileges => [ 'Select_priv', 'Reload_priv', 'Lock_tables_priv', 'Show_view_priv' ]
18+
)}
19+
20+
it { should contain_cron('mysql-backup').with(
21+
:command => '/usr/local/sbin/mysqlbackup.sh',
22+
:ensure => 'present'
23+
)}
24+
25+
it { should contain_file('mysqlbackup.sh').with(
26+
:path => '/usr/local/sbin/mysqlbackup.sh',
27+
:ensure => 'present'
28+
) }
29+
30+
it { should contain_file('mysqlbackupdir').with(
31+
:path => '/tmp',
32+
:ensure => 'directory'
33+
)}
34+
35+
it 'should have compression by default' do
36+
verify_contents(subject, 'mysqlbackup.sh', [
37+
' --all-databases | bzcat -zc > ${DIR}/mysql_backup_`date +%Y%m%d-%H%M%S`.sql.bz2',
38+
])
39+
end
40+
end
41+
42+
context "with compression disabled" do
43+
let(:params) do
44+
{ :backupcompress => false }.merge(default_params)
45+
end
46+
47+
it { should contain_file('mysqlbackup.sh').with(
48+
:path => '/usr/local/sbin/mysqlbackup.sh',
49+
:ensure => 'present'
50+
) }
51+
52+
it 'should be able to disable compression' do
53+
verify_contents(subject, 'mysqlbackup.sh', [
54+
' --all-databases > ${DIR}/mysql_backup_`date +%Y%m%d-%H%M%S`.sql',
55+
])
56+
end
57+
end
3358
end

templates/mysqlbackup.sh.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ PATH=/usr/bin:/usr/sbin:/bin:/sbin
1919

2020
find $DIR -mtime +30 -exec rm -f {} \;
2121
mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \
22-
--all-databases | bzcat -zc > ${DIR}/mysql_backup_`date +%Y%m%d-%H%M%S`.sql.bz2
22+
--all-databases <% if backupcompress %>| bzcat -zc <% end %>> ${DIR}/mysql_backup_`date +%Y%m%d-%H%M%S`.sql<% if backupcompress %>.bz2<% end %>
2323

0 commit comments

Comments
 (0)