瀏覽代碼

Improve remote restore of mariadb

Bob Mottram 8 年之前
父節點
當前提交
4945db5817
共有 3 個檔案被更改,包括 19 行新增15 行删除
  1. 0
    9
      src/freedombone-restore-local
  2. 9
    5
      src/freedombone-restore-remote
  3. 10
    1
      src/freedombone-utils-database

+ 0
- 9
src/freedombone-restore-local 查看文件

249
     fi
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
 function restore_passwordstore {
252
 function restore_passwordstore {
262
     if [[ $RESTORE_APP != 'all' ]]; then
253
     if [[ $RESTORE_APP != 'all' ]]; then
263
         if [[ $RESTORE_APP != 'passwords' ]]; then
254
         if [[ $RESTORE_APP != 'passwords' ]]; then

+ 9
- 5
src/freedombone-restore-remote 查看文件

185
         temp_restore_dir=/root/tempmariadb
185
         temp_restore_dir=/root/tempmariadb
186
         restore_directory_from_friend $temp_restore_dir mariadb
186
         restore_directory_from_friend $temp_restore_dir mariadb
187
 
187
 
188
+        store_original_mariadb_password
189
+
188
         echo $'Obtaining MariaDB password'
190
         echo $'Obtaining MariaDB password'
189
-        db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
191
+        db_pass=$(cat /root/.mariadboriginal)
190
         if [ ${#db_pass} -gt 0 ]; then
192
         if [ ${#db_pass} -gt 0 ]; then
191
             echo $"Restore the MariaDB user table"
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
             if [ ! "$?" = "0" ]; then
195
             if [ ! "$?" = "0" ]; then
194
                 echo $"Try again using the password obtained from backup"
196
                 echo $"Try again using the password obtained from backup"
197
+                db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
195
                 mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
198
                 mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}${temp_restore_dir}/mysql.sql)
196
             fi
199
             fi
197
             if [ ! "$?" = "0" ]; then
200
             if [ ! "$?" = "0" ]; then
200
             fi
203
             fi
201
             echo $"Restarting database"
204
             echo $"Restarting database"
202
             systemctl restart mariadb
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
         fi
209
         fi
207
         rm -rf ${temp_restore_dir}
210
         rm -rf ${temp_restore_dir}
208
     fi
211
     fi
227
         fi
230
         fi
228
     fi
231
     fi
229
     if [ -d $SERVER_DIRECTORY/backup/passwordstore ]; then
232
     if [ -d $SERVER_DIRECTORY/backup/passwordstore ]; then
233
+        store_original_mariadb_password
230
         echo $"Restoring password store"
234
         echo $"Restoring password store"
231
         restore_directory_from_friend / passwordstore
235
         restore_directory_from_friend / passwordstore
232
     fi
236
     fi

+ 10
- 1
src/freedombone-utils-database 查看文件

13
 # License
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
 # This program is free software: you can redistribute it and/or modify
18
 # This program is free software: you can redistribute it and/or modify
19
 # it under the terms of the GNU Affero General Public License as published by
19
 # it under the terms of the GNU Affero General Public License as published by
34
 # Used to indicate whether the backup contains MariaDB databases or not
34
 # Used to indicate whether the backup contains MariaDB databases or not
35
 BACKUP_INCLUDES_DATABASES="no"
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
 function keep_database_running {
46
 function keep_database_running {
38
     if [ ! $(daemon_is_running mariadb) ]; then
47
     if [ ! $(daemon_is_running mariadb) ]; then
39
         systemctl start mariadb
48
         systemctl start mariadb