Skip to content

Commit 0149481

Browse files
committed
Use temp cnf file instead of env variable which creates acceptance test failures.
1 parent d1f1601 commit 0149481

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

templates/mysqlbackup.sh.erb

+9-8
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ PASS='<%= @backuppassword %>'
1919
DIR=<%= @backupdir %>
2020
ROTATE=<%= [ Integer(@backuprotate) - 1, 0 ].max %>
2121

22-
# Set MYSQL_PWD env variable. See https://dev.mysql.com/doc/refman/5.1/en/password-security-user.html
23-
export MYSQL_PWD="$PASS"
22+
# Create temporary mysql cnf file.
23+
TMPFILE=`mktemp /tmp/backup.XXXXXX` || exit 1
24+
echo -e "[client]\npassword=$PASS\nuser=$USER" > $TMPFILE
2425

2526
PREFIX=mysql_backup_
2627
<% if @ignore_events %>
@@ -64,20 +65,20 @@ cleanup
6465
<% end -%>
6566
<% if @backupdatabases.empty? -%>
6667
<% if @file_per_database -%>
67-
mysql -u${USER} -s -r -N -e 'SHOW DATABASES' | while read dbname
68+
mysql --defaults-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read dbname
6869
do
69-
mysqldump -u${USER} --opt --flush-logs --single-transaction \
70+
mysqldump --defaults-file=$TMPFILE --opt --flush-logs --single-transaction \
7071
${ADDITIONAL_OPTIONS} \
7172
${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
7273
done
7374
<% else -%>
74-
mysqldump -u${USER} --opt --flush-logs --single-transaction \
75+
mysqldump --defaults-file=$TMPFILE --opt --flush-logs --single-transaction \
7576
${ADDITIONAL_OPTIONS} \
7677
--all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
7778
<% end -%>
7879
<% else -%>
7980
<% @backupdatabases.each do |db| -%>
80-
mysqldump -u${USER} --opt --flush-logs --single-transaction \
81+
mysqldump --defaults-file=$TMPFILE --opt --flush-logs --single-transaction \
8182
${ADDITIONAL_OPTIONS} \
8283
<%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %>
8384
<% end -%>
@@ -95,5 +96,5 @@ fi
9596
<%- end -%>
9697
<% end -%>
9798

98-
# Unset MYSQL_PWD env variable
99-
unset MYSQL_PWD
99+
# Remove temporary file
100+
rm -f $TMPFILE

0 commit comments

Comments
 (0)