|
2 | 2 |
|
3 | 3 | describe 'mysql::server::backup' do
|
4 | 4 |
|
5 |
| - let(:default_params) { |
6 |
| - { 'backupuser' => 'testuser', |
7 |
| - 'backuppassword' => 'testpass', |
8 |
| - 'backupdir' => '/tmp', |
9 |
| - 'backuprotate' => '25', |
10 |
| - 'delete_before_dump' => true, |
| 5 | + let(:default_params) { |
| 6 | + { 'backupuser' => 'testuser', |
| 7 | + 'backuppassword' => 'testpass', |
| 8 | + 'backupdir' => '/tmp', |
| 9 | + 'backuprotate' => '25', |
| 10 | + 'delete_before_dump' => true, |
| 11 | + } |
11 | 12 | }
|
12 |
| - } |
13 |
| - context 'standard conditions' do |
14 |
| - let(:params) { default_params } |
15 |
| - |
16 |
| - it { should contain_mysql_user('testuser@localhost').with( |
17 |
| - :require => 'Class[Mysql::Server::Root_password]' |
18 |
| - )} |
19 |
| - |
20 |
| - it { should contain_mysql_grant('testuser@localhost/*.*').with( |
21 |
| - :privileges => ["SELECT", "RELOAD", "LOCK TABLES", "SHOW VIEW"] |
22 |
| - )} |
23 |
| - |
24 |
| - it { should contain_cron('mysql-backup').with( |
25 |
| - :command => '/usr/local/sbin/mysqlbackup.sh', |
26 |
| - :ensure => 'present' |
27 |
| - )} |
28 |
| - |
29 |
| - it { should contain_file('mysqlbackup.sh').with( |
30 |
| - :path => '/usr/local/sbin/mysqlbackup.sh', |
31 |
| - :ensure => 'present' |
32 |
| - ) } |
33 |
| - |
34 |
| - it { should contain_file('mysqlbackupdir').with( |
35 |
| - :path => '/tmp', |
36 |
| - :ensure => 'directory' |
37 |
| - )} |
38 |
| - |
39 |
| - it 'should have compression by default' do |
40 |
| - verify_contents(subject, 'mysqlbackup.sh', [ |
41 |
| - ' --all-databases | bzcat -zc > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql.bz2', |
42 |
| - ]) |
| 13 | + context 'standard conditions' do |
| 14 | + let(:params) { default_params } |
| 15 | + |
| 16 | + it { should contain_mysql_user('testuser@localhost').with( |
| 17 | + :require => 'Class[Mysql::Server::Root_password]' |
| 18 | + )} |
| 19 | + |
| 20 | + it { should contain_mysql_grant('testuser@localhost/*.*').with( |
| 21 | + :privileges => ["SELECT", "RELOAD", "LOCK TABLES", "SHOW VIEW"] |
| 22 | + )} |
| 23 | + |
| 24 | + it { should contain_cron('mysql-backup').with( |
| 25 | + :command => '/usr/local/sbin/mysqlbackup.sh', |
| 26 | + :ensure => 'present' |
| 27 | + )} |
| 28 | + |
| 29 | + it { should contain_file('mysqlbackup.sh').with( |
| 30 | + :path => '/usr/local/sbin/mysqlbackup.sh', |
| 31 | + :ensure => 'present' |
| 32 | + ) } |
| 33 | + |
| 34 | + it { should contain_file('mysqlbackupdir').with( |
| 35 | + :path => '/tmp', |
| 36 | + :ensure => 'directory' |
| 37 | + )} |
| 38 | + |
| 39 | + it 'should have compression by default' do |
| 40 | + verify_contents(subject, 'mysqlbackup.sh', [ |
| 41 | + ' --all-databases | bzcat -zc > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql.bz2', |
| 42 | + ]) |
| 43 | + end |
| 44 | + it 'should skip backing up events table by default' do |
| 45 | + verify_contents(subject, 'mysqlbackup.sh', [ |
| 46 | + 'EVENTS="--ignore-table=mysql.event"', |
| 47 | + ]) |
| 48 | + end |
| 49 | + |
| 50 | + it 'should have 25 days of rotation' do |
| 51 | + # MySQL counts from 0 I guess. |
| 52 | + should contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/) |
| 53 | + end |
43 | 54 | end
|
44 | 55 |
|
45 |
| - it 'should have 25 days of rotation' do |
46 |
| - # MySQL counts from 0 I guess. |
47 |
| - should contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/) |
| 56 | + context 'custom ownership and mode for backupdir' do |
| 57 | + let(:params) do |
| 58 | + { :backupdirmode => '0750', |
| 59 | + :backupdirowner => 'testuser', |
| 60 | + :backupdirgroup => 'testgrp', |
| 61 | + }.merge(default_params) |
| 62 | + end |
| 63 | + |
| 64 | + it { should contain_file('mysqlbackupdir').with( |
| 65 | + :path => '/tmp', |
| 66 | + :ensure => 'directory', |
| 67 | + :mode => '0750', |
| 68 | + :owner => 'testuser', |
| 69 | + :group => 'testgrp' |
| 70 | + ) } |
48 | 71 | end
|
49 |
| - end |
50 |
| - |
51 |
| - context 'custom ownership and mode for backupdir' do |
52 |
| - let(:params) do |
53 |
| - { :backupdirmode => '0750', |
54 |
| - :backupdirowner => 'testuser', |
55 |
| - :backupdirgroup => 'testgrp', |
56 |
| - }.merge(default_params) |
| 72 | + |
| 73 | + context 'with compression disabled' do |
| 74 | + let(:params) do |
| 75 | + { :backupcompress => false }.merge(default_params) |
| 76 | + end |
| 77 | + |
| 78 | + it { should contain_file('mysqlbackup.sh').with( |
| 79 | + :path => '/usr/local/sbin/mysqlbackup.sh', |
| 80 | + :ensure => 'present' |
| 81 | + ) } |
| 82 | + |
| 83 | + it 'should be able to disable compression' do |
| 84 | + verify_contents(subject, 'mysqlbackup.sh', [ |
| 85 | + ' --all-databases > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql', |
| 86 | + ]) |
| 87 | + end |
57 | 88 | end
|
58 | 89 |
|
59 |
| - it { should contain_file('mysqlbackupdir').with( |
60 |
| - :path => '/tmp', |
61 |
| - :ensure => 'directory', |
62 |
| - :mode => '0750', |
63 |
| - :owner => 'testuser', |
64 |
| - :group => 'testgrp' |
65 |
| - ) } |
66 |
| - end |
67 |
| - |
68 |
| - context 'with compression disabled' do |
69 |
| - let(:params) do |
70 |
| - { :backupcompress => false }.merge(default_params) |
| 90 | + context 'with mysql.events backedup' do |
| 91 | + let(:params) do |
| 92 | + { :ignore_events => false }.merge(default_params) |
| 93 | + end |
| 94 | + |
| 95 | + it { should contain_file('mysqlbackup.sh').with( |
| 96 | + :path => '/usr/local/sbin/mysqlbackup.sh', |
| 97 | + :ensure => 'present' |
| 98 | + ) } |
| 99 | + |
| 100 | + it 'should be able to backup events table' do |
| 101 | + verify_contents(subject, 'mysqlbackup.sh', [ |
| 102 | + 'EVENTS="--events"', |
| 103 | + ]) |
| 104 | + end |
71 | 105 | end
|
72 | 106 |
|
73 |
| - it { should contain_file('mysqlbackup.sh').with( |
74 |
| - :path => '/usr/local/sbin/mysqlbackup.sh', |
75 |
| - :ensure => 'present' |
76 |
| - ) } |
77 | 107 |
|
78 |
| - it 'should be able to disable compression' do |
79 |
| - verify_contents(subject, 'mysqlbackup.sh', [ |
80 |
| - ' --all-databases > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql', |
81 |
| - ]) |
82 |
| - end |
83 |
| - end |
| 108 | + context 'with database list specified' do |
| 109 | + let(:params) do |
| 110 | + { :backupdatabases => ['mysql'] }.merge(default_params) |
| 111 | + end |
84 | 112 |
|
85 |
| - context 'with database list specified' do |
86 |
| - let(:params) do |
87 |
| - { :backupdatabases => ['mysql'] }.merge(default_params) |
88 |
| - end |
| 113 | + it { should contain_file('mysqlbackup.sh').with( |
| 114 | + :path => '/usr/local/sbin/mysqlbackup.sh', |
| 115 | + :ensure => 'present' |
| 116 | + ) } |
89 | 117 |
|
90 |
| - it { should contain_file('mysqlbackup.sh').with( |
91 |
| - :path => '/usr/local/sbin/mysqlbackup.sh', |
92 |
| - :ensure => 'present' |
93 |
| - ) } |
94 |
| - |
95 |
| - it 'should have a backup file for each database' do |
96 |
| - content = subject.resource('file','mysqlbackup.sh').send(:parameters)[:content] |
97 |
| - content.should match(' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date') |
98 |
| -# verify_contents(subject, 'mysqlbackup.sh', [ |
99 |
| -# ' mysql | bzcat -zc ${DIR}/${PREFIX}mysql_`date +%Y%m%d-%H%M%S`.sql', |
100 |
| -# ]) |
101 |
| - end |
102 |
| - end |
103 |
| - |
104 |
| - context 'with file per database' do |
105 |
| - let(:params) do |
106 |
| - default_params.merge({ :file_per_database => true }) |
| 118 | + it 'should have a backup file for each database' do |
| 119 | + content = subject.resource('file','mysqlbackup.sh').send(:parameters)[:content] |
| 120 | + content.should match(' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date') |
| 121 | + # verify_contents(subject, 'mysqlbackup.sh', [ |
| 122 | + # ' mysql | bzcat -zc ${DIR}/${PREFIX}mysql_`date +%Y%m%d-%H%M%S`.sql', |
| 123 | + # ]) |
| 124 | + end |
107 | 125 | end
|
108 |
| - |
109 |
| - it 'should loop through backup all databases' do |
110 |
| - verify_contents(subject, 'mysqlbackup.sh', [ |
111 |
| - 'mysql -s -r -N -e \'SHOW DATABASES\' | while read dbname', |
112 |
| - 'do', |
113 |
| - ' mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \\', |
114 |
| - ' ${dbname} | bzcat -zc > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql.bz2', |
115 |
| - 'done', |
116 |
| - ]) |
117 |
| - end |
118 |
| - |
119 |
| - context 'with compression disabled' do |
120 |
| - let(:params) do |
121 |
| - default_params.merge({ :file_per_database => true, :backupcompress => false }) |
122 |
| - end |
123 |
| - |
124 |
| - it 'should loop through backup all databases without compression' do |
125 |
| - verify_contents(subject, 'mysqlbackup.sh', [ |
126 |
| - ' ${dbname} > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql', |
127 |
| - ]) |
128 |
| - end |
| 126 | + |
| 127 | + context 'with file per database' do |
| 128 | + let(:params) do |
| 129 | + default_params.merge({ :file_per_database => true }) |
| 130 | + end |
| 131 | + |
| 132 | + it 'should loop through backup all databases' do |
| 133 | + verify_contents(subject, 'mysqlbackup.sh', [ |
| 134 | + 'mysql -s -r -N -e \'SHOW DATABASES\' | while read dbname', |
| 135 | + 'do', |
| 136 | + ' mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \\', |
| 137 | + ' ${EVENTS} \\', |
| 138 | + ' ${dbname} | bzcat -zc > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql.bz2', |
| 139 | + 'done', |
| 140 | + ]) |
| 141 | + end |
| 142 | + |
| 143 | + context 'with compression disabled' do |
| 144 | + let(:params) do |
| 145 | + default_params.merge({ :file_per_database => true, :backupcompress => false }) |
| 146 | + end |
| 147 | + |
| 148 | + it 'should loop through backup all databases without compression' do |
| 149 | + verify_contents(subject, 'mysqlbackup.sh', [ |
| 150 | + ' ${dbname} > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql', |
| 151 | + ]) |
| 152 | + end |
| 153 | + end |
129 | 154 | end
|
130 |
| - end |
131 | 155 | end
|
0 commit comments