From 01bd117d0f87a57098d47500146a3f2e18940330 Mon Sep 17 00:00:00 2001 From: Ze'ev Schurmann Date: Mon, 16 Oct 2023 17:59:49 +0200 Subject: [PATCH] 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. --- sqldumps/sqldumps.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) mode change 100644 => 100755 sqldumps/sqldumps.sh diff --git a/sqldumps/sqldumps.sh b/sqldumps/sqldumps.sh old mode 100644 new mode 100755 index a7c5e95..ea98589 --- a/sqldumps/sqldumps.sh +++ b/sqldumps/sqldumps.sh @@ -44,6 +44,30 @@ ignorelist=("mysql" "performance_schema" "dbispconfig" "phpmyadmin" "roundcube") 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. rm -f *.sql @@ -52,7 +76,7 @@ rm -f *.list ## 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. @@ -60,6 +84,7 @@ mysql -e "show databases" | grep -Ev 'Database|information_schema' > db.list for ((n=0; n<${#ignorelist[@]}; n++)) do echo ${ignorelist[$n]} >> db.list + echo ${ignorelist[$n]} >> db.list done @@ -68,7 +93,7 @@ done sort db.list | uniq -u | while read -r dbname; do echo "Dumping $dbname to $dumppath/$dbname.sql" - mysqldump $dbname > "$dumppath/$dbname.sql" + mysqldump $sqlup $dbname > "$dumppath/$dbname.sql" done rm db.list