File tree 3 files changed +34
-5
lines changed
3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change 3
3
# This module handles ...
4
4
#
5
5
# Parameters:
6
- # [*backupuser*] - The name of the mysql backup user.
7
- # [*backuppassword*] - The password of the mysql backup user.
8
- # [*backupdir*] - The target directory of the mysqldump.
9
- # [*backupcompress*] - Boolean to compress backup with bzip2.
10
- # [*backuprotate*] - Number of backups to keep. Default 30
6
+ # [*backupuser*] - The name of the mysql backup user.
7
+ # [*backuppassword*] - The password of the mysql backup user.
8
+ # [*backupdir*] - The target directory of the mysqldump.
9
+ # [*backupcompress*] - Boolean to compress backup with bzip2.
10
+ # [*backuprotate*] - Number of backups to keep. Default 30
11
+ # [*backupdatabases*] - Specify databases to back up as array (default all)
11
12
# [*delete_before_dump*] - Clean existing backups before creating new
12
13
#
13
14
# Actions:
32
33
$backupcompress = true ,
33
34
$backuprotate = 30,
34
35
$delete_before_dump = false ,
36
+ $backupdatabases = [],
35
37
$ensure = ' present'
36
38
) {
37
39
72
74
owner => ' root' ,
73
75
group => ' root' ,
74
76
}
77
+
75
78
}
Original file line number Diff line number Diff line change 62
62
] )
63
63
end
64
64
end
65
+
66
+ context 'with database list specified' do
67
+ let ( :params ) do
68
+ { :backupdatabases => [ 'mysql' ] } . merge ( default_params )
69
+ end
70
+
71
+ it { should contain_file ( 'mysqlbackup.sh' ) . with (
72
+ :path => '/usr/local/sbin/mysqlbackup.sh' ,
73
+ :ensure => 'present'
74
+ ) }
75
+
76
+ it 'should have a backup file for each database' do
77
+ content = catalogue . resource ( 'file' , 'mysqlbackup.sh' ) . send ( :parameters ) [ :content ]
78
+ content . should match ( ' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date' )
79
+ # verify_contents(subject, 'mysqlbackup.sh', [
80
+ # ' mysql | bzcat -zc ${DIR}/${PREFIX}mysql_`date +%Y%m%d-%H%M%S`.sql',
81
+ # ])
82
+ end
83
+ end
65
84
end
Original file line number Diff line number Diff line change @@ -31,8 +31,15 @@ cleanup()
31
31
cleanup
32
32
33
33
< % end -%>
34
+ < % if @backupdatabases.empty? -%>
34
35
mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \
35
36
--all-databases < % if @backupcompress %> | bzcat -zc < % end %>> ${DIR} /${PREFIX} ` date +%Y%m%d-%H%M%S` .sql< % if @backupcompress %> .bz2< % end %>
37
+ < % else -%>
38
+ < % @backupdatabases.each do | db| -%>
39
+ mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \
40
+ < %= db %><% if @backupcompress %> | bzcat -zc < % end %>> ${DIR} /${PREFIX} < %= db %> _` date +%Y%m%d-%H%M%S` .sql< % if @backupcompress %> .bz2< % end %>
41
+ < % end -%>
42
+ < % end -%>
36
43
37
44
< % unless @delete_before_dump -%>
38
45
if [ $? -eq 0 ] ; then
You can’t perform that action at this time.
0 commit comments