Browse Source

Consolidation of backup functions

Bob Mottram 8 years ago
parent
commit
ec1ecf577b
4 changed files with 178 additions and 187 deletions
  1. 1
    0
      src/freedombone-app-sip
  2. 1
    100
      src/freedombone-restore-local
  3. 2
    87
      src/freedombone-restore-remote
  4. 174
    0
      src/freedombone-utils-backup

+ 1
- 0
src/freedombone-app-sip View File

@@ -77,6 +77,7 @@ function restore_local_sip {
77 77
 		fi
78 78
 		rm -rf $temp_restore_dir
79 79
 		service sipwitch restart
80
+		echo $"Restore of SIP settings complete"
80 81
 	fi
81 82
 }
82 83
 

+ 1
- 100
src/freedombone-restore-local View File

@@ -100,83 +100,6 @@ function restore_directory_from_usb {
100 100
 	obnam restore -r $USB_MOUNT/backup/${2} --to ${1}
101 101
 }
102 102
 
103
-function restore_database {
104
-	RESTORE_SUBDIR="root"
105
-
106
-	if [ -d $USB_MOUNT/backup/${1} ]; then
107
-		echo $"Restoring ${1} database"
108
-		restore_directory_from_usb "/root/temp${1}data" "${1}data"
109
-		if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then
110
-			echo $"Unable to restore ${1} database"
111
-			rm -rf /root/temp${1}data
112
-			set_user_permissions
113
-			backup_unmount_drive
114
-			exit 503
115
-		fi
116
-		mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
117
-		if [ ! "$?" = "0" ]; then
118
-			echo "$mysqlsuccess"
119
-			set_user_permissions
120
-			backup_unmount_drive
121
-			exit 964
122
-		fi
123
-		shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*
124
-		rm -rf /root/temp${1}data
125
-		echo $"Restoring ${1} installation"
126
-		if [ ! -d /root/temp${1} ]; then
127
-			mkdir /root/temp${1}
128
-		fi
129
-		restore_directory_from_usb "/root/temp${1}" "${1}"
130
-		RESTORE_SUBDIR="var"
131
-		if [ ${2} ]; then
132
-			# special handline of ttrss
133
-			if [[ ${2} == "ttrss" ]]; then
134
-				if [ -d /etc/share/tt-rss ]; then
135
-					if [ -d /root/temp${1}/etc/share/tt-rss ]; then
136
-						rm -rf /etc/share/tt-rss
137
-						mv /root/temp${1}/etc/share/tt-rss /etc/share/
138
-						if [ ! "$?" = "0" ]; then
139
-							set_user_permissions
140
-							backup_unmount_drive
141
-							exit 528
142
-						fi
143
-						if [ -d /etc/letsencrypt/live/${2} ]; then
144
-							ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
145
-							ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
146
-						else
147
-							# Ensure that the bundled SSL cert is being used
148
-							if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
149
-								sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
150
-							fi
151
-						fi
152
-					fi
153
-				fi
154
-			fi
155
-
156
-			if [ -d /var/www/${2}/htdocs ]; then
157
-				if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then
158
-					rm -rf /var/www/${2}/htdocs
159
-					mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/
160
-					if [ ! "$?" = "0" ]; then
161
-						set_user_permissions
162
-						backup_unmount_drive
163
-						exit 683
164
-					fi
165
-					if [ -d /etc/letsencrypt/live/${2} ]; then
166
-						ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
167
-						ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
168
-					else
169
-						# Ensure that the bundled SSL cert is being used
170
-						if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
171
-							sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
172
-						fi
173
-					fi
174
-				fi
175
-			fi
176
-		fi
177
-	fi
178
-}
179
-
180 103
 function restore_configuration {
181 104
 	if [[ $RESTORE_APP != 'all' ]]; then
182 105
 		if [[ $RESTORE_APP != 'configuration' ]]; then
@@ -771,28 +694,6 @@ function get_restore_app {
771 694
 	fi
772 695
 }
773 696
 
774
-function restore_apps {
775
-	FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
776
-
777
-	APPS_COMPLETED=()
778
-
779
-	# for all the app scripts
780
-	for filename in $FILES
781
-	do
782
-		app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
783
-		if [[ $RESTORE_APP == 'all' || $RESTORE_APP == "${app_name}"  ]]; then
784
-			if [[ $(item_in_array ${app_name} ${APPS_COMPLETED[@]}) != 0 ]]; then
785
-				function_check app_is_installed
786
-				if [[ "$(app_is_installed $a)" == "1" ]]; then
787
-					APPS_COMPLETED+=("${app_name}")
788
-					function_check restore_local_${app_name}
789
-					restore_local_${app_name}
790
-				fi
791
-			fi
792
-		fi
793
-	done
794
-}
795
-
796 697
 get_restore_app ${2}
797 698
 backup_mount_drive ${1} ${ADMIN_USERNAME} ${2}
798 699
 check_backup_exists
@@ -817,7 +718,7 @@ restore_certs
817 718
 restore_personal_settings
818 719
 restore_mailing_list
819 720
 restore_email
820
-restore_apps
721
+restore_apps local
821 722
 set_user_permissions
822 723
 backup_unmount_drive
823 724
 

+ 2
- 87
src/freedombone-restore-remote View File

@@ -105,72 +105,6 @@ function copy_gpg_keys {
105 105
 	cp -r /home/$ADMIN_USERNAME/.gnupg /root
106 106
 }
107 107
 
108
-function restore_database_from_friend {
109
-	DATABASE_PASSWORD=
110
-	RESTORE_SUBDIR="root"
111
-
112
-	if [ -d $SERVER_DIRECTORY/backup/${1} ]; then
113
-		echo $"Restoring ${1} database"
114
-		restore_directory_from_friend /root/temp${1}data ${1}data
115
-		if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then
116
-			echo $"Unable to restore ${1} database"
117
-			rm -rf /root/temp${1}data
118
-			exit 503
119
-		fi
120
-		mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
121
-		if [ ! "$?" = "0" ]; then
122
-			echo "$mysqlsuccess"
123
-			exit 964
124
-		fi
125
-		shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*
126
-		rm -rf /root/temp${1}data
127
-		echo $"Restoring ${1} installation"
128
-		restore_directory_from_friend /root/temp${1} ${1}
129
-		RESTORE_SUBDIR="var"
130
-		if [ ${1} ]; then
131
-
132
-			# special handling of ttrss
133
-			if [[ ${2} == "ttrss" ]]; then
134
-				if [ -d /etc/share/tt-rss ]; then
135
-					rm -rf /etc/share/tt-rss
136
-					mv /root/temp${1}/etc/share/tt-rss /etc/share/
137
-					if [ ! "$?" = "0" ]; then
138
-						exit 639
139
-					fi
140
-					if [ -d /etc/letsencrypt/live/${2} ]; then
141
-						ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
142
-						ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
143
-					else
144
-						# Ensure that the bundled SSL cert is being used
145
-						if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
146
-							sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
147
-						fi
148
-					fi
149
-				fi
150
-			fi
151
-
152
-			if [ -d /var/www/${2}/htdocs ]; then
153
-				if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then
154
-					rm -rf /var/www/${2}/htdocs
155
-					mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/
156
-					if [ ! "$?" = "0" ]; then
157
-						exit 683
158
-					fi
159
-					if [ -d /etc/letsencrypt/live/${2} ]; then
160
-						ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
161
-						ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
162
-					else
163
-						# Ensure that the bundled SSL cert is being used
164
-						if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
165
-							sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
166
-						fi
167
-					fi
168
-				fi
169
-			fi
170
-		fi
171
-	fi
172
-}
173
-
174 108
 function restore_configuration {
175 109
 	if [[ $RESTORE_APP != 'all' ]]; then
176 110
 		if [[ $RESTORE_APP != 'configuration' ]]; then
@@ -695,26 +629,6 @@ function restore_email {
695 629
 	done
696 630
 }
697 631
 
698
-function restore_dlna {
699
-	if [[ $RESTORE_APP != 'all' ]]; then
700
-		if [[ $RESTORE_APP != 'dlna' ]]; then
701
-			return
702
-		fi
703
-	fi
704
-	if [ -d /var/cache/minidlna ]; then
705
-		if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
706
-			echo $"Restoring DLNA cache"
707
-			temp_restore_dir=/root/tempdlna
708
-			restore_directory_from_friend $temp_restore_dir dlna
709
-			cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
710
-			if [ ! "$?" = "0" ]; then
711
-				exit 982
712
-			fi
713
-			rm -rf $temp_restore_dir
714
-		fi
715
-	fi
716
-}
717
-
718 632
 # Social key management
719 633
 # Recover any key fragments and reconstruct the gpg key
720 634
 ${PROJECT_NAME}-recoverkey -u ${ADMIN_USERNAME} -l $BACKUP_LIST
@@ -737,7 +651,8 @@ restore_certs
737 651
 restore_personal_settings
738 652
 restore_mailing_list
739 653
 restore_email
740
-#restore_apps remote
654
+restore_apps remote
655
+set_user_permissions
741 656
 
742 657
 echo $"*** Remote restore was successful ***"
743 658
 

+ 174
- 0
src/freedombone-utils-backup View File

@@ -382,4 +382,178 @@ function backup_apps {
382 382
 	done
383 383
 }
384 384
 
385
+function restore_apps {
386
+	localremote=$1
387
+	FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
388
+
389
+	RESTORE_APPS_COMPLETED=()
390
+
391
+	# for all the app scripts
392
+	for filename in $FILES
393
+	do
394
+		app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
395
+		if [[ $RESTORE_APP == 'all' || $RESTORE_APP == "${app_name}"  ]]; then
396
+			if [[ $(item_in_array ${app_name} ${RESTORE_APPS_COMPLETED[@]}) != 0 ]]; then
397
+				function_check app_is_installed
398
+				if [[ "$(app_is_installed $a)" == "1" ]]; then
399
+					RESTORE_APPS_COMPLETED+=("${app_name}")
400
+					function_check restore_${localremote}_${app_name}
401
+					restore_${localremote}_${app_name}
402
+				fi
403
+			fi
404
+		fi
405
+	done
406
+}
407
+
408
+function restore_database_from_friend {
409
+	DATABASE_PASSWORD=
410
+	RESTORE_SUBDIR="root"
411
+
412
+	if [ -d $SERVER_DIRECTORY/backup/${1} ]; then
413
+		echo $"Restoring ${1} database"
414
+		restore_directory_from_friend /root/temp${1}data ${1}data
415
+		if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then
416
+			echo $"Unable to restore ${1} database"
417
+			rm -rf /root/temp${1}data
418
+			exit 503
419
+		fi
420
+		mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
421
+		if [ ! "$?" = "0" ]; then
422
+			echo "$mysqlsuccess"
423
+			exit 964
424
+		fi
425
+		shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*
426
+		rm -rf /root/temp${1}data
427
+		echo $"Restoring ${1} installation"
428
+		restore_directory_from_friend /root/temp${1} ${1}
429
+		RESTORE_SUBDIR="var"
430
+		if [ ${1} ]; then
431
+
432
+			# special handling of ttrss
433
+			if [[ ${2} == "ttrss" ]]; then
434
+				if [ -d /etc/share/tt-rss ]; then
435
+					rm -rf /etc/share/tt-rss
436
+					mv /root/temp${1}/etc/share/tt-rss /etc/share/
437
+					if [ ! "$?" = "0" ]; then
438
+						exit 639
439
+					fi
440
+					if [ -d /etc/letsencrypt/live/${2} ]; then
441
+						ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
442
+						ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
443
+					else
444
+						# Ensure that the bundled SSL cert is being used
445
+						if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
446
+							sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
447
+						fi
448
+					fi
449
+				fi
450
+			fi
451
+
452
+			if [ -d /var/www/${2}/htdocs ]; then
453
+				if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then
454
+					rm -rf /var/www/${2}/htdocs
455
+					mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/
456
+					if [ ! "$?" = "0" ]; then
457
+						exit 683
458
+					fi
459
+					if [ -d /etc/letsencrypt/live/${2} ]; then
460
+						ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
461
+						ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
462
+					else
463
+						# Ensure that the bundled SSL cert is being used
464
+						if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
465
+							sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
466
+						fi
467
+					fi
468
+				fi
469
+			fi
470
+		fi
471
+	fi
472
+}
473
+
474
+function restore_database {
475
+	RESTORE_SUBDIR="root"
476
+
477
+	if [ -d $USB_MOUNT/backup/${1} ]; then
478
+		echo $"Restoring ${1} database"
479
+		function_check restore_directory_from_usb
480
+		restore_directory_from_usb "/root/temp${1}data" "${1}data"
481
+		if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then
482
+			echo $"Unable to restore ${1} database"
483
+			rm -rf /root/temp${1}data
484
+			function_check set_user_permissions
485
+			set_user_permissions
486
+			function_check backup_unmount_drive
487
+			backup_unmount_drive
488
+			exit 503
489
+		fi
490
+		mysqlsuccess=$(mysql -u root --password=$DATABASE_PASSWORD ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
491
+		if [ ! "$?" = "0" ]; then
492
+			echo "$mysqlsuccess"
493
+			function_check set_user_permissions
494
+			set_user_permissions
495
+			function_check set_user_permissions
496
+			backup_unmount_drive
497
+			exit 964
498
+		fi
499
+		shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/*
500
+		rm -rf /root/temp${1}data
501
+		echo $"Restoring ${1} installation"
502
+		if [ ! -d /root/temp${1} ]; then
503
+			mkdir /root/temp${1}
504
+		fi
505
+		function_check restore_directory_from_usb
506
+		restore_directory_from_usb "/root/temp${1}" "${1}"
507
+		RESTORE_SUBDIR="var"
508
+		if [ ${2} ]; then
509
+			# special handline of ttrss
510
+			if [[ ${2} == "ttrss" ]]; then
511
+				if [ -d /etc/share/tt-rss ]; then
512
+					if [ -d /root/temp${1}/etc/share/tt-rss ]; then
513
+						rm -rf /etc/share/tt-rss
514
+						mv /root/temp${1}/etc/share/tt-rss /etc/share/
515
+						if [ ! "$?" = "0" ]; then
516
+							function_check set_user_permissions
517
+							set_user_permissions
518
+							function_check backup_unmount_drive
519
+							backup_unmount_drive
520
+							exit 528
521
+						fi
522
+						if [ -d /etc/letsencrypt/live/${2} ]; then
523
+							ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
524
+							ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
525
+						else
526
+							# Ensure that the bundled SSL cert is being used
527
+							if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
528
+								sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
529
+							fi
530
+						fi
531
+					fi
532
+				fi
533
+			fi
534
+
535
+			if [ -d /var/www/${2}/htdocs ]; then
536
+				if [ -d /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs ]; then
537
+					rm -rf /var/www/${2}/htdocs
538
+					mv /root/temp${1}/${RESTORE_SUBDIR}/www/${2}/htdocs /var/www/${2}/
539
+					if [ ! "$?" = "0" ]; then
540
+						set_user_permissions
541
+						backup_unmount_drive
542
+						exit 683
543
+					fi
544
+					if [ -d /etc/letsencrypt/live/${2} ]; then
545
+						ln -s /etc/letsencrypt/live/${2}/privkey.pem /etc/ssl/private/${2}.key
546
+						ln -s /etc/letsencrypt/live/${2}/fullchain.pem /etc/ssl/certs/${2}.pem
547
+					else
548
+						# Ensure that the bundled SSL cert is being used
549
+						if [ -f /etc/ssl/certs/${2}.bundle.crt ]; then
550
+							sed -i "s|${2}.crt|${2}.bundle.crt|g" /etc/nginx/sites-available/${2}
551
+						fi
552
+					fi
553
+				fi
554
+			fi
555
+		fi
556
+	fi
557
+}
558
+
385 559
 # NOTE: deliberately no exit 0