Skip to content

Use temp cnf file instead of env variable. #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions templates/mysqlbackup.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ PASS='<%= @backuppassword %>'
DIR=<%= @backupdir %>
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
export MYSQL_PWD="$PASS"
# Create temporary mysql cnf file.
TMPFILE=`mktemp /tmp/backup.XXXXXX` || exit 1
echo -e "[client]\npassword=$PASS\nuser=$USER" > $TMPFILE

PREFIX=mysql_backup_
<% if @ignore_events %>
Expand Down Expand Up @@ -64,20 +65,20 @@ cleanup
<% end -%>
<% if @backupdatabases.empty? -%>
<% 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
mysqldump -u${USER} --opt --flush-logs --single-transaction \
mysqldump --defaults-file=$TMPFILE --opt --flush-logs --single-transaction \
${ADDITIONAL_OPTIONS} \
${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
done
<% else -%>
mysqldump -u${USER} --opt --flush-logs --single-transaction \
mysqldump --defaults-file=$TMPFILE --opt --flush-logs --single-transaction \
${ADDITIONAL_OPTIONS} \
--all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
<% end -%>
<% else -%>
<% @backupdatabases.each do |db| -%>
mysqldump -u${USER} --opt --flush-logs --single-transaction \
mysqldump --defaults-file=$TMPFILE --opt --flush-logs --single-transaction \
${ADDITIONAL_OPTIONS} \
<%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
<% end -%>
Expand All @@ -95,5 +96,5 @@ fi
<%- end -%>
<% end -%>

# Unset MYSQL_PWD env variable
unset MYSQL_PWD
# Remove temporary file
rm -f $TMPFILE