Added support to back up specified databases only with 'mysqlbackup'
parameter. Each database is backed up separately to a named file.
This commit is contained in:
parent
e0aed9f06b
commit
359d88175c
3 changed files with 34 additions and 5 deletions
|
@ -3,11 +3,12 @@
|
|||
# This module handles ...
|
||||
#
|
||||
# Parameters:
|
||||
# [*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.
|
||||
# [*backuprotate*] - Number of backups to keep. Default 30
|
||||
# [*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.
|
||||
# [*backuprotate*] - Number of backups to keep. Default 30
|
||||
# [*backupdatabases*] - Specify databases to back up as array (default all)
|
||||
# [*delete_before_dump*] - Clean existing backups before creating new
|
||||
#
|
||||
# Actions:
|
||||
|
@ -32,6 +33,7 @@ class mysql::backup (
|
|||
$backupcompress = true,
|
||||
$backuprotate = 30,
|
||||
$delete_before_dump = false,
|
||||
$backupdatabases = false,
|
||||
$ensure = 'present'
|
||||
) {
|
||||
|
||||
|
@ -72,4 +74,5 @@ class mysql::backup (
|
|||
owner => 'root',
|
||||
group => 'root',
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,4 +62,23 @@ describe 'mysql::backup' do
|
|||
])
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
content = catalogue.resource('file','mysqlbackup.sh').send(:parameters)[:content]
|
||||
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
|
||||
end
|
||||
|
|
|
@ -31,8 +31,15 @@ cleanup()
|
|||
cleanup
|
||||
|
||||
<% end -%>
|
||||
<% if @backupdatabases -%>
|
||||
<% @backupdatabases.each do |db| -%>
|
||||
mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \
|
||||
<%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
|
||||
<% end -%>
|
||||
<% else -%>
|
||||
mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \
|
||||
--all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
|
||||
<% end -%>
|
||||
|
||||
<% unless @delete_before_dump -%>
|
||||
if [ $? -eq 0 ] ; then
|
||||
|
|
Loading…
Reference in a new issue