Mercurial > repos > other > Puppet
comparison modules/mysql/templates/mysqlbackup.sh.erb @ 0:956e484adc12
Initial public release of Puppet configs
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 16 Aug 2014 19:47:38 +0000 |
parents | |
children | 58d1818c2ded |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:956e484adc12 |
---|---|
1 #!/bin/bash | |
2 # | |
3 # MySQL Backup Script | |
4 # Dumps mysql databases to a file for another backup tool to pick up. | |
5 # | |
6 # MySQL code: | |
7 # GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost' | |
8 # IDENTIFIED BY 'password'; | |
9 # FLUSH PRIVILEGES; | |
10 # | |
11 ##### START CONFIG ################################################### | |
12 | |
13 USER=<%= @backupuser %> | |
14 PASS='<%= @backuppassword %>' | |
15 DIR=<%= @backupdir %> | |
16 ROTATE=<%= [ Integer(@backuprotate) - 1, 0 ].max %> | |
17 | |
18 PREFIX=mysql_backup_ | |
19 <% if @ignore_events %> | |
20 EVENTS="--ignore-table=mysql.event" | |
21 <% else %> | |
22 EVENTS="--events" | |
23 <% end %> | |
24 | |
25 ##### STOP CONFIG #################################################### | |
26 PATH=<%= @execpath %> | |
27 | |
28 | |
29 | |
30 set -o pipefail | |
31 | |
32 cleanup() | |
33 { | |
34 find "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | xargs -0 -r rm -f | |
35 } | |
36 | |
37 <% if @delete_before_dump -%> | |
38 cleanup | |
39 | |
40 <% end -%> | |
41 <% if @backupdatabases.empty? -%> | |
42 <% if @file_per_database -%> | |
43 mysql -s -r -N -e 'SHOW DATABASES' | while read dbname | |
44 do | |
45 mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \ | |
46 ${EVENTS} \ | |
47 ${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> | |
48 done | |
49 <% else -%> | |
50 mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \ | |
51 ${EVENTS} \ | |
52 --all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> | |
53 <% end -%> | |
54 <% else -%> | |
55 <% @backupdatabases.each do |db| -%> | |
56 mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \ | |
57 ${EVENTS} \ | |
58 <%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> | |
59 <% end -%> | |
60 <% end -%> | |
61 | |
62 <% unless @delete_before_dump -%> | |
63 if [ $? -eq 0 ] ; then | |
64 cleanup | |
65 fi | |
66 <% end -%> | |
67 | |
68 <% if @postscript -%> | |
69 <%- [@postscript].flatten.compact.each do |script|%> | |
70 <%= script %> | |
71 <%- end -%> | |
72 <% end -%> |