Merge pull request #778 from mentat/acceptance-fix

Use temp cnf file instead of env variable.
This commit is contained in:
Hunter Haugen 2015-11-13 08:10:25 -08:00
commit 2f144b3a38

View file

@ -19,8 +19,9 @@ PASS='<%= @backuppassword %>'
DIR=<%= @backupdir %> DIR=<%= @backupdir %>
ROTATE=<%= [ Integer(@backuprotate) - 1, 0 ].max %> ROTATE=<%= [ Integer(@backuprotate) - 1, 0 ].max %>
# Set MYSQL_PWD env variable. See https://dev.mysql.com/doc/refman/5.1/en/password-security-user.html # Create temporary mysql cnf file.
export MYSQL_PWD="$PASS" TMPFILE=`mktemp /tmp/backup.XXXXXX` || exit 1
echo -e "[client]\npassword=$PASS\nuser=$USER" > $TMPFILE
PREFIX=mysql_backup_ PREFIX=mysql_backup_
<% if @ignore_events %> <% if @ignore_events %>
@ -64,20 +65,20 @@ cleanup
<% end -%> <% end -%>
<% if @backupdatabases.empty? -%> <% if @backupdatabases.empty? -%>
<% if @file_per_database -%> <% if @file_per_database -%>
mysql -u${USER} -s -r -N -e 'SHOW DATABASES' | while read dbname mysql --defaults-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read dbname
do do
mysqldump -u${USER} --opt --flush-logs --single-transaction \ mysqldump --defaults-file=$TMPFILE --opt --flush-logs --single-transaction \
${ADDITIONAL_OPTIONS} \ ${ADDITIONAL_OPTIONS} \
${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> ${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
done done
<% else -%> <% else -%>
mysqldump -u${USER} --opt --flush-logs --single-transaction \ mysqldump --defaults-file=$TMPFILE --opt --flush-logs --single-transaction \
${ADDITIONAL_OPTIONS} \ ${ADDITIONAL_OPTIONS} \
--all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> --all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
<% end -%> <% end -%>
<% else -%> <% else -%>
<% @backupdatabases.each do |db| -%> <% @backupdatabases.each do |db| -%>
mysqldump -u${USER} --opt --flush-logs --single-transaction \ mysqldump --defaults-file=$TMPFILE --opt --flush-logs --single-transaction \
${ADDITIONAL_OPTIONS} \ ${ADDITIONAL_OPTIONS} \
<%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> <%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
<% end -%> <% end -%>
@ -95,5 +96,5 @@ fi
<%- end -%> <%- end -%>
<% end -%> <% end -%>
# Unset MYSQL_PWD env variable # Remove temporary file
unset MYSQL_PWD rm -f $TMPFILE