Przeglądaj źródła

Improve remote restore of mariadb

Bob Mottram 7 lat temu
rodzic
commit
4945db5817

+ 0
- 9
src/freedombone-restore-local Wyświetl plik

@@ -249,15 +249,6 @@ function restore_letsencrypt {
249 249
     fi
250 250
 }
251 251
 
252
-function store_original_mariadb_password {
253
-    if [ ! -f /root/.mariadboriginal ]; then
254
-        echo $'Storing original mariadb password'
255
-        ORIGINAL_MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
256
-        # We can store this in plaintext because it will soon be of historical interest only
257
-        echo -n "$ORIGINAL_MARIADB_PASSWORD" > /root/.mariadboriginal
258
-    fi
259
-}
260
-
261 252
 function restore_passwordstore {
262 253
     if [[ $RESTORE_APP != 'all' ]]; then
263 254
         if [[ $RESTORE_APP != 'passwords' ]]; then

+ 9
- 5
src/freedombone-restore-remote Wyświetl plik

@@ -185,13 +185,16 @@ function restore_mariadb {
185 185
         temp_restore_dir=/root/tempmariadb
186 186
         restore_directory_from_friend $temp_restore_dir mariadb
187 187
 
188
+        store_original_mariadb_password
189
+
188 190
         echo $'Obtaining MariaDB password'
189
-        db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
191
+        db_pass=$(cat /root/.mariadboriginal)
190 192
         if [ ${#db_pass} -gt 0 ]; then
191 193
             echo $"Restore the MariaDB user table"
192
-            mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
194
+            mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
193 195
             if [ ! "$?" = "0" ]; then
194 196
                 echo $"Try again using the password obtained from backup"
197
+                db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
195 198
                 mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
196 199
             fi
197 200
             if [ ! "$?" = "0" ]; then
@@ -200,9 +203,9 @@ function restore_mariadb {
200 203
             fi
201 204
             echo $"Restarting database"
202 205
             systemctl restart mariadb
203
-            echo $"Change the MariaDB password to the backup version"
204
-            DATABASE_PASSWORD="$db_pass"
205
-            ${PROJECT_NAME}-pass -u root -a mariadb -p "$DATABASE_PASSWORD"
206
+            echo $"Ensure MariaDB handles authentication"
207
+            MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
208
+            mariadb_fix_authentication
206 209
         fi
207 210
         rm -rf ${temp_restore_dir}
208 211
     fi
@@ -227,6 +230,7 @@ function restore_passwordstore {
227 230
         fi
228 231
     fi
229 232
     if [ -d $SERVER_DIRECTORY/backup/passwordstore ]; then
233
+        store_original_mariadb_password
230 234
         echo $"Restoring password store"
231 235
         restore_directory_from_friend / passwordstore
232 236
     fi

+ 10
- 1
src/freedombone-utils-database Wyświetl plik

@@ -13,7 +13,7 @@
13 13
 # License
14 14
 # =======
15 15
 #
16
-# Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
16
+# Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
17 17
 #
18 18
 # This program is free software: you can redistribute it and/or modify
19 19
 # it under the terms of the GNU Affero General Public License as published by
@@ -34,6 +34,15 @@ MARIADB_PASSWORD=
34 34
 # Used to indicate whether the backup contains MariaDB databases or not
35 35
 BACKUP_INCLUDES_DATABASES="no"
36 36
 
37
+function store_original_mariadb_password {
38
+    if [ ! -f /root/.mariadboriginal ]; then
39
+        echo $'Storing original mariadb password'
40
+        ORIGINAL_MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
41
+        # We can store this in plaintext because it will soon be of historical interest only
42
+        echo -n "$ORIGINAL_MARIADB_PASSWORD" > /root/.mariadboriginal
43
+    fi
44
+}
45
+
37 46
 function keep_database_running {
38 47
     if [ ! $(daemon_is_running mariadb) ]; then
39 48
         systemctl start mariadb