Selaa lähdekoodia

Improve restore of mariadb

Bob Mottram 8 vuotta sitten
vanhempi
commit
604a1929ba
2 muutettua tiedostoa jossa 21 lisäystä ja 10 poistoa
  1. 1
    1
      src/freedombone-pass
  2. 20
    9
      src/freedombone-restore-local

+ 1
- 1
src/freedombone-pass Näytä tiedosto

22
 # License
22
 # License
23
 # =======
23
 # =======
24
 #
24
 #
25
-# Copyright (C) 2016 Bob Mottram <bob@freedombone.net>
25
+# Copyright (C) 2016-2017 Bob Mottram <bob@freedombone.net>
26
 #
26
 #
27
 # This program is free software: you can redistribute it and/or modify
27
 # This program is free software: you can redistribute it and/or modify
28
 # it under the terms of the GNU Affero General Public License as published by
28
 # it under the terms of the GNU Affero General Public License as published by

+ 20
- 9
src/freedombone-restore-local Näytä tiedosto

83
     ADMIN_USERNAME=$(get_completion_param "Admin user")
83
     ADMIN_USERNAME=$(get_completion_param "Admin user")
84
 fi
84
 fi
85
 
85
 
86
-# MariaDB password
87
-DATABASE_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
88
-
89
 function check_backup_exists {
86
 function check_backup_exists {
90
     if [ ! -d $USB_MOUNT/backup ]; then
87
     if [ ! -d $USB_MOUNT/backup ]; then
91
         echo $"No backup directory found on the USB drive."
88
         echo $"No backup directory found on the USB drive."
209
         keep_database_running
206
         keep_database_running
210
         temp_restore_dir=/root/tempmariadb
207
         temp_restore_dir=/root/tempmariadb
211
         restore_directory_from_usb $temp_restore_dir mariadb
208
         restore_directory_from_usb $temp_restore_dir mariadb
212
-        echo $'Obtaining MariaDB password'
213
-        db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
209
+
210
+        store_original_mariadb_password
211
+
212
+        echo $'Obtaining original MariaDB password'
213
+        db_pass=$(cat /root/.mariadboriginal)
214
         if [ ${#db_pass} -gt 0 ]; then
214
         if [ ${#db_pass} -gt 0 ]; then
215
             echo $"Restore the MariaDB user table"
215
             echo $"Restore the MariaDB user table"
216
-            mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
216
+            mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
217
             if [ ! "$?" = "0" ]; then
217
             if [ ! "$?" = "0" ]; then
218
                 echo $"Try again using the password obtained from backup"
218
                 echo $"Try again using the password obtained from backup"
219
+                db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
219
                 mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
220
                 mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
220
             fi
221
             fi
221
             if [ ! "$?" = "0" ]; then
222
             if [ ! "$?" = "0" ]; then
226
             fi
227
             fi
227
             echo $"Restarting database"
228
             echo $"Restarting database"
228
             systemctl restart mariadb
229
             systemctl restart mariadb
229
-            echo $"Change the MariaDB password to the backup version"
230
-            DATABASE_PASSWORD="$db_pass"
231
-            ${PROJECT_NAME}-pass -u root -a mariadb -p "$DATABASE_PASSWORD"
230
+            echo $"Ensure MariaDB handles authentication"
231
+            MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
232
+            mariadb_fix_authentication
232
         fi
233
         fi
233
         rm -rf $temp_restore_dir
234
         rm -rf $temp_restore_dir
234
     fi
235
     fi
248
     fi
249
     fi
249
 }
250
 }
250
 
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
+
251
 function restore_passwordstore {
261
 function restore_passwordstore {
252
     if [[ $RESTORE_APP != 'all' ]]; then
262
     if [[ $RESTORE_APP != 'all' ]]; then
253
         if [[ $RESTORE_APP != 'passwords' ]]; then
263
         if [[ $RESTORE_APP != 'passwords' ]]; then
255
         fi
265
         fi
256
     fi
266
     fi
257
     if [ -d $USB_MOUNT/backup/passwordstore ]; then
267
     if [ -d $USB_MOUNT/backup/passwordstore ]; then
268
+        store_original_mariadb_password
258
         echo $"Restoring password store"
269
         echo $"Restoring password store"
259
         restore_directory_from_usb / passwordstore
270
         restore_directory_from_usb / passwordstore
260
     fi
271
     fi