Selaa lähdekoodia

Restore database

Bob Mottram 8 vuotta sitten
vanhempi
commit
80553d9d8b
1 muutettua tiedostoa jossa 23 lisäystä ja 21 poistoa
  1. 23
    21
      src/freedombone-utils-backup

+ 23
- 21
src/freedombone-utils-backup Näytä tiedosto

@@ -517,14 +517,16 @@ function restore_database_from_friend {
517 517
 
518 518
 function restore_database {
519 519
     RESTORE_SUBDIR="root"
520
+    restore_app_name=$1
521
+    restore_app_dir=$2
520 522
 
521
-    if [ -d $USB_MOUNT/backup/${1} ]; then
523
+    if [ -d $USB_MOUNT/backup/${restore_app_name} ]; then
522 524
         echo $"Restoring ${1} database"
523
-        local_database_dir=/root/temp${1}data
525
+        local_database_dir=/root/temp${restore_app_name}data
524 526
         function_check restore_directory_from_usb
525
-        restore_directory_from_usb "${local_database}" "${1}data"
526
-        if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then
527
-            echo $"Unable to restore ${1} database"
527
+        restore_directory_from_usb "${local_database}" "${restore_app_name}data"
528
+        if [ ! -f /root/temp${restore_app_name}data/${RESTORE_SUBDIR}/temp${restore_app_name}data/${restore_app_name}.sql ]; then
529
+            echo $"Unable to restore ${restore_app_name} database"
528 530
             rm -rf ${local_database}
529 531
             function_check set_user_permissions
530 532
             set_user_permissions
@@ -532,7 +534,7 @@ function restore_database {
532 534
             backup_unmount_drive
533 535
             exit 503
534 536
         fi
535
-        mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < ${local_database}/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
537
+        mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${restore_app_name} -o < ${local_database}/${RESTORE_SUBDIR}/temp${restore_app_name}data/${restore_app_name}.sql)
536 538
         if [ ! "$?" = "0" ]; then
537 539
             echo "$mysqlsuccess"
538 540
             function_check set_user_permissions
@@ -541,32 +543,32 @@ function restore_database {
541 543
             backup_unmount_drive
542 544
             exit 964
543 545
         fi
544
-        shred -zu ${local_database}/${RESTORE_SUBDIR}/temp${1}data/*
546
+        shred -zu ${local_database}/${RESTORE_SUBDIR}/temp${restore_app_name}data/*
545 547
         rm -rf ${local_database}
546
-        echo $"Restoring ${1} installation"
547
-        if [ ! -d /root/temp${1} ]; then
548
-            mkdir /root/temp${1}
548
+        echo $"Restoring ${restore_app_name} installation"
549
+        if [ ! -d /root/temp${restore_app_name} ]; then
550
+            mkdir /root/temp${restore_app_name}
549 551
         fi
550 552
         function_check restore_directory_from_usb
551
-        restore_directory_from_usb "/root/temp${1}" "${1}"
553
+        restore_directory_from_usb "/root/temp${restore_app_name}" "${restore_app_name}"
552 554
         RESTORE_SUBDIR="var"
553
-        if [ ${2} ]; then
554
-            if [ -d /var/www/${2}/htdocs ]; then
555
-                if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then
556
-                    rm -rf /var/www/${2}/htdocs
557
-                    mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/
555
+        if [ ${restore_app_dir} ]; then
556
+            if [ -d /var/www/${restore_app_dir}/htdocs ]; then
557
+                if [ -d /root/temp${restore_app_name}/${RESTORE_SUBDIR}/www/${restore_app_dir}/htdocs ]; then
558
+                    rm -rf /var/www/${restore_app_dir}/htdocs
559
+                    mv /root/temp${restore_app_name}/${RESTORE_SUBDIR}/www/${restore_app_dir}/htdocs /var/www/${restore_app_dir}/
558 560
                     if [ ! "$?" = "0" ]; then
559 561
                         set_user_permissions
560 562
                         backup_unmount_drive
561 563
                         exit 683
562 564
                     fi
563
-                    if [ -d /etc/letsencrypt/live/${2} ]; then
564
-                        ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
565
-                        ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
565
+                    if [ -d /etc/letsencrypt/live/${restore_app_dir} ]; then
566
+                        ln -s /etc/letsencrypt/live/${restore_app_dir}/privkey.pem /etc/ssl/private/${restore_app_dir}.key
567
+                        ln -s /etc/letsencrypt/live/${restore_app_dir}/fullchain.pem /etc/ssl/certs/${restore_app_dir}.pem
566 568
                     else
567 569
                         # Ensure that the bundled SSL cert is being used
568
-                        if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
569
-                            sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
570
+                        if [ -f /etc/ssl/certs/${restore_app_dir}.bundle.crt ]; then
571
+                            sed -i "s|${restore_app_dir}.crt|${restore_app_dir}.bundle.crt|g" /etc/nginx/sites-available/${restore_app_dir}
570 572
                         fi
571 573
                     fi
572 574
                 fi