Improve remote restore of mariadb
This commit is contained in:
parent
604a1929ba
commit
4945db5817
|
@ -249,15 +249,6 @@ function restore_letsencrypt {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function store_original_mariadb_password {
|
|
||||||
if [ ! -f /root/.mariadboriginal ]; then
|
|
||||||
echo $'Storing original mariadb password'
|
|
||||||
ORIGINAL_MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
|
|
||||||
# We can store this in plaintext because it will soon be of historical interest only
|
|
||||||
echo -n "$ORIGINAL_MARIADB_PASSWORD" > /root/.mariadboriginal
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function restore_passwordstore {
|
function restore_passwordstore {
|
||||||
if [[ $RESTORE_APP != 'all' ]]; then
|
if [[ $RESTORE_APP != 'all' ]]; then
|
||||||
if [[ $RESTORE_APP != 'passwords' ]]; then
|
if [[ $RESTORE_APP != 'passwords' ]]; then
|
||||||
|
|
|
@ -185,13 +185,16 @@ function restore_mariadb {
|
||||||
temp_restore_dir=/root/tempmariadb
|
temp_restore_dir=/root/tempmariadb
|
||||||
restore_directory_from_friend $temp_restore_dir mariadb
|
restore_directory_from_friend $temp_restore_dir mariadb
|
||||||
|
|
||||||
|
store_original_mariadb_password
|
||||||
|
|
||||||
echo $'Obtaining MariaDB password'
|
echo $'Obtaining MariaDB password'
|
||||||
db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
|
db_pass=$(cat /root/.mariadboriginal)
|
||||||
if [ ${#db_pass} -gt 0 ]; then
|
if [ ${#db_pass} -gt 0 ]; then
|
||||||
echo $"Restore the MariaDB user table"
|
echo $"Restore the MariaDB user table"
|
||||||
mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
|
mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
|
||||||
if [ ! "$?" = "0" ]; then
|
if [ ! "$?" = "0" ]; then
|
||||||
echo $"Try again using the password obtained from backup"
|
echo $"Try again using the password obtained from backup"
|
||||||
|
db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
|
||||||
mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
|
mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
|
||||||
fi
|
fi
|
||||||
if [ ! "$?" = "0" ]; then
|
if [ ! "$?" = "0" ]; then
|
||||||
|
@ -200,9 +203,9 @@ function restore_mariadb {
|
||||||
fi
|
fi
|
||||||
echo $"Restarting database"
|
echo $"Restarting database"
|
||||||
systemctl restart mariadb
|
systemctl restart mariadb
|
||||||
echo $"Change the MariaDB password to the backup version"
|
echo $"Ensure MariaDB handles authentication"
|
||||||
DATABASE_PASSWORD="$db_pass"
|
MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
|
||||||
${PROJECT_NAME}-pass -u root -a mariadb -p "$DATABASE_PASSWORD"
|
mariadb_fix_authentication
|
||||||
fi
|
fi
|
||||||
rm -rf ${temp_restore_dir}
|
rm -rf ${temp_restore_dir}
|
||||||
fi
|
fi
|
||||||
|
@ -227,6 +230,7 @@ function restore_passwordstore {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -d $SERVER_DIRECTORY/backup/passwordstore ]; then
|
if [ -d $SERVER_DIRECTORY/backup/passwordstore ]; then
|
||||||
|
store_original_mariadb_password
|
||||||
echo $"Restoring password store"
|
echo $"Restoring password store"
|
||||||
restore_directory_from_friend / passwordstore
|
restore_directory_from_friend / passwordstore
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
# License
|
# License
|
||||||
# =======
|
# =======
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
|
# Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -34,6 +34,15 @@ MARIADB_PASSWORD=
|
||||||
# Used to indicate whether the backup contains MariaDB databases or not
|
# Used to indicate whether the backup contains MariaDB databases or not
|
||||||
BACKUP_INCLUDES_DATABASES="no"
|
BACKUP_INCLUDES_DATABASES="no"
|
||||||
|
|
||||||
|
function store_original_mariadb_password {
|
||||||
|
if [ ! -f /root/.mariadboriginal ]; then
|
||||||
|
echo $'Storing original mariadb password'
|
||||||
|
ORIGINAL_MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
|
||||||
|
# We can store this in plaintext because it will soon be of historical interest only
|
||||||
|
echo -n "$ORIGINAL_MARIADB_PASSWORD" > /root/.mariadboriginal
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function keep_database_running {
|
function keep_database_running {
|
||||||
if [ ! $(daemon_is_running mariadb) ]; then
|
if [ ! $(daemon_is_running mariadb) ]; then
|
||||||
systemctl start mariadb
|
systemctl start mariadb
|
||||||
|
|
Loading…
Reference in New Issue