Merge "MariaDB backup and restore with grants of all users"
This commit is contained in:
commit
b8ec250d01
@ -38,7 +38,7 @@ dump_databases_to_directory() {
|
||||
|
||||
MYSQL_DBNAMES=( $($MYSQL --silent --skip-column-names -e \
|
||||
"show databases;" | \
|
||||
egrep -vi 'information_schema|performance_schema') )
|
||||
egrep -vi 'information_schema|performance_schema|mysql') )
|
||||
|
||||
#check if there is a database to backup, otherwise exit
|
||||
if [[ -z "${MYSQL_DBNAMES// }" ]]
|
||||
@ -50,6 +50,13 @@ dump_databases_to_directory() {
|
||||
#Create a list of Databases
|
||||
printf "%s\n" "${MYSQL_DBNAMES[@]}" > $TMP_DIR/db.list
|
||||
|
||||
#Retrieve and create the GRANT file for all the users
|
||||
if ! pt-show-grants --defaults-file=/etc/mysql/admin_user.cnf \
|
||||
2>>"$LOG_FILE" > "$TMP_DIR"/grants.sql; then
|
||||
log ERROR "Failed to create GRANT for all the users"
|
||||
return 1
|
||||
fi
|
||||
|
||||
#Retrieve and create the GRANT files per DB
|
||||
for db in "${MYSQL_DBNAMES[@]}"
|
||||
do
|
||||
@ -62,6 +69,7 @@ dump_databases_to_directory() {
|
||||
sed -i 's/$/;/' $TMP_DIR/${db}_grant.sql
|
||||
else
|
||||
log ERROR "Failed to create GRANT files for ${db}"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -221,6 +221,10 @@ restore_single_db() {
|
||||
$MYSQL < ${TMP_DIR}/${SINGLE_DB_NAME}_grant.sql 2>>$RESTORE_LOG
|
||||
if [[ "$?" -eq 0 ]]
|
||||
then
|
||||
if ! $MYSQL --execute="FLUSH PRIVILEGES;"; then
|
||||
echo "Failed to flush privileges for $SINGLE_DB_NAME."
|
||||
return 1
|
||||
fi
|
||||
echo "Database $SINGLE_DB_NAME Permission Restore successful."
|
||||
else
|
||||
cat $RESTORE_LOG
|
||||
@ -254,27 +258,25 @@ restore_all_dbs() {
|
||||
echo "Databases $( echo $DBS | tr -d '\n') Restore failed."
|
||||
return 1
|
||||
fi
|
||||
if [ -n "$DBS" ]
|
||||
if [[ -f ${TMP_DIR}/grants.sql ]]
|
||||
then
|
||||
for db in $DBS
|
||||
do
|
||||
if [ -f ${TMP_DIR}/${db}_grant.sql ]
|
||||
then
|
||||
$MYSQL < ${TMP_DIR}/${db}_grant.sql 2>>$RESTORE_LOG
|
||||
$MYSQL < ${TMP_DIR}/grants.sql 2>$RESTORE_LOG
|
||||
if [[ "$?" -eq 0 ]]
|
||||
then
|
||||
echo "Database $db Permission Restore successful."
|
||||
if ! $MYSQL --execute="FLUSH PRIVILEGES;"; then
|
||||
echo "Failed to flush privileges."
|
||||
return 1
|
||||
fi
|
||||
echo "Databases Permission Restore successful."
|
||||
else
|
||||
cat $RESTORE_LOG
|
||||
echo "Database $db Permission Restore failed."
|
||||
echo "Databases Permission Restore failed."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "There is no permission file available for $db"
|
||||
echo "There is no permission file available"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
else
|
||||
echo "There is no database file available to restore from"
|
||||
return 1
|
||||
|
Loading…
Reference in New Issue
Block a user