Fixed a bug where if the ignore database is not in the server then it would attempt to dump it.
Added support for mysql authentication.
This commit is contained in:
parent
009de60f5f
commit
01bd117d0f
|
@ -44,6 +44,30 @@ ignorelist=("mysql" "performance_schema" "dbispconfig" "phpmyadmin" "roundcube")
|
||||||
dumppath="/var/sqldumps"
|
dumppath="/var/sqldumps"
|
||||||
|
|
||||||
|
|
||||||
|
## MySQL Credentials
|
||||||
|
|
||||||
|
## If the username is left blank (null) then no MySQL login will be attempted.
|
||||||
|
## If the password is left blank (null) then no Password will be used in the login attempt.
|
||||||
|
|
||||||
|
sqlusername="root"
|
||||||
|
sqlpassword="djhfasdghfkjlahsdfjkh"
|
||||||
|
|
||||||
|
|
||||||
|
## Determines login method.
|
||||||
|
|
||||||
|
if [[ -z $sqlusername ]]
|
||||||
|
then
|
||||||
|
sqlup=""
|
||||||
|
else
|
||||||
|
if [[ -z $sqlpassword ]]
|
||||||
|
then
|
||||||
|
sqlup="-u $sqlusername"
|
||||||
|
else
|
||||||
|
sqlup="-u $sqlusername -p$sqlpassword"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
## Removes previous SQL dumps and list files.
|
## Removes previous SQL dumps and list files.
|
||||||
|
|
||||||
rm -f *.sql
|
rm -f *.sql
|
||||||
|
@ -52,7 +76,7 @@ rm -f *.list
|
||||||
|
|
||||||
## Creates a list file of all the databases.
|
## Creates a list file of all the databases.
|
||||||
|
|
||||||
mysql -e "show databases" | grep -Ev 'Database|information_schema' > db.list
|
mysql $sqlup -e "show databases" | grep -Ev 'Database|information_schema' > db.list
|
||||||
|
|
||||||
|
|
||||||
## Add a list of the unwanted databases to the list file.
|
## Add a list of the unwanted databases to the list file.
|
||||||
|
@ -60,6 +84,7 @@ mysql -e "show databases" | grep -Ev 'Database|information_schema' > db.list
|
||||||
for ((n=0; n<${#ignorelist[@]}; n++))
|
for ((n=0; n<${#ignorelist[@]}; n++))
|
||||||
do
|
do
|
||||||
echo ${ignorelist[$n]} >> db.list
|
echo ${ignorelist[$n]} >> db.list
|
||||||
|
echo ${ignorelist[$n]} >> db.list
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +93,7 @@ done
|
||||||
|
|
||||||
sort db.list | uniq -u | while read -r dbname; do
|
sort db.list | uniq -u | while read -r dbname; do
|
||||||
echo "Dumping $dbname to $dumppath/$dbname.sql"
|
echo "Dumping $dbname to $dumppath/$dbname.sql"
|
||||||
mysqldump $dbname > "$dumppath/$dbname.sql"
|
mysqldump $sqlup $dbname > "$dumppath/$dbname.sql"
|
||||||
done
|
done
|
||||||
|
|
||||||
rm db.list
|
rm db.list
|
||||||
|
|
Loading…
Reference in New Issue