Skip to content

Commit 235fd0a

Browse files
author
Eshlee Romero
committed
fixes
1 parent cabd9aa commit 235fd0a

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

mysql_backup.sh

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ osname=`uname`
66
date_today=$(date)
77
script=${0}
88
scriptpath=$(dirname "$script")
9-
logpath=$scriptpath'/backup_log.txt'
9+
logpath=$scriptpath'/backup.log'
1010

1111
function HELP {
1212
echo "This is help"
@@ -39,6 +39,7 @@ while getopts h:u:P:p:d:H opt; do
3939
HELP
4040
esac
4141
done
42+
4243
if [ -z "$username" ]; then
4344
echo -n 'Enter Administrative username : '
4445
read username
@@ -52,16 +53,13 @@ fi
5253
if [ -z "$password" ]; then
5354
echo -n 'Enter MySQL Password : '
5455
read -s password
55-
56-
if [ -z "$password" ]; then
57-
echo
58-
fi
56+
echo
5957
fi
6058

61-
if [ -z "$databases" ]; then
59+
while [ -z "$databases" ]; do
6260
echo 'Specify Database comma separated (-d) : '
6361
read databases
64-
fi
62+
done
6563

6664
# Convert comma separated string to array
6765
IFS=', ' read -a databases <<< "$databases"
@@ -76,8 +74,23 @@ for ((i=0; i<max; i++))
7674
do
7775
started_date=$(date +'%m-%d-%y')'_'$(date +'%T')
7876
filename=$scriptpath'/'${databases[$i]}'_'$started_date'.sql'
79-
# echo $filename
80-
sudo mysqldump -h $host -u$username -p$password ${databases[$i]} > $filename
77+
78+
command='/usr/local/bin/mysqldump '
79+
80+
if [ ! -z "$host" ]; then
81+
command=$command' -h'$host
82+
fi
83+
84+
command=$command' -u'$username
85+
86+
if [ ! -z "$password" ]; then
87+
command=$command' -p'$password
88+
fi
89+
90+
command=$command' '${databases[$i]}
91+
92+
$command > $filename # put dump to file
93+
8194
retval=$?
8295
echo $retval
8396
if [ $retval -eq 0 ]; then

0 commit comments

Comments
 (0)