These utilities might be useful for things ranging from database dumps/backups to making it possible to set certain programs that require arguments (`rsync`, `rsnapshot`) as the command for a key in SSH `athorized_keys`.
\ No newline at end of file
These utilities might be useful for things ranging from database dumps/backups to making it possible to set certain programs that require arguments (`rsync`, `rsnapshot`) as the command for a key in SSH `athorized_keys`.
# databases are dumped as schema (containing grants related to the database and CREATE statements) and data dump spearately,
# put in $1/schemas/$database_name.schema.sql and $1/dumps/$database_name.dump.sql respectively
# put in $4/schemas/$database_name.schema.sql and $4/dumps/$database_name.dump.sql respectively
#
# this does *not* dump internal MySQL information_schema and performance_schema databases.
function dump_mysql_dbs {
...
...
@@ -151,9 +151,9 @@ function dump_mysql_dbs {
clean_db_vars
# create the directory structure
mkdir-p"$1"
mkdir-p"$1/schemas"
mkdir-p"$1/dumps"
mkdir-p"$4"
mkdir-p"$4/schemas"
mkdir-p"$4/dumps"
#
# - if we have no additional arguments (5th and onwards), we need to dump all the databases (well, apart from information_schema and performance_schema)
...
...
@@ -164,7 +164,7 @@ function dump_mysql_dbs {
fi
# get the list of databases
DATABASES="$( mysql -h"$2"-u"$3"--password="$4"--batch-e"SHOW DATABASES $DATABASES_WHERE;" | egrep -v'(Database|information_schema|performance_schema)')"
DATABASES="$( mysql -h"$1"-u"$2"--password="$3"--batch-e"SHOW DATABASES $DATABASES_WHERE;" | egrep -v'(Database|information_schema|performance_schema)')"
# either the code is 0, or the command failed; act accordingly.
[$?-eq 0 ]|| display_error_and_quit
...
...
@@ -191,7 +191,7 @@ function dump_mysql_dbs {
echo" +-- found `echo"$DATABASES" | wc-l` databases..."
# is the db using authentication_string, or password for user passwords?
if[["$( mysql -h"$2"-u"$3"--password="$4"--batch--skip-column-names-e"SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'mysql' AND TABLE_NAME = 'user' AND COLUMN_NAME = 'password';")"=="0"]];then
if[["$( mysql -h"$1"-u"$2"--password="$3"--batch--skip-column-names-e"SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'mysql' AND TABLE_NAME = 'user' AND COLUMN_NAME = 'password';")"=="0"]];then
PWCOL="authentication_string"
else
PWCOL="password"
...
...
@@ -199,7 +199,7 @@ function dump_mysql_dbs {
echo" +-- password column: $PWCOL"
# get the list of users
DBUSERS="$( mysql -h"$2"-u"$3"--password="$4"--batch--skip-column-names-e"SELECT CONCAT('',QUOTE(user),'@',QUOTE(host),':',$PWCOL) FROM mysql.user WHERE user<>'';")"
DBUSERS="$( mysql -h"$1"-u"$2"--password="$3"--batch--skip-column-names-e"SELECT CONCAT('',QUOTE(user),'@',QUOTE(host),':',$PWCOL) FROM mysql.user WHERE user<>'';")"
# get the grants # add IDENTIFIED BY <password>, but only when there was no IDENTIFIED BY there already
DBGRANTS=`echo-ne"$DBGRANTS\n$( mysql -h"$2"-u"$3"--password="$4"--batch--skip-column-names-e"SHOW GRANTS FOR $DBUSER;" | sed-r-e"s/(IDENTIFIED BY.*)$/ IDENTIFIED BY PASSWORD '$DBUSERPW'/g")"`
DBGRANTS=`echo-ne"$DBGRANTS\n$( mysql -h"$1"-u"$2"--password="$3"--batch--skip-column-names-e"SHOW GRANTS FOR $DBUSER;" | sed-r-e"s/(IDENTIFIED BY.*)$/ IDENTIFIED BY PASSWORD '$DBUSERPW'/g")"`