Ver código fonte

Local backup of gnusocial

Bob Mottram 8 anos atrás
pai
commit
8a165eddb9
Nenhuma conta conectada ao e-mail do autor de commit

+ 624
- 600
src/freedombone-app-gnusocial
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


+ 10
- 76
src/freedombone-backup-local Ver arquivo

@@ -97,81 +97,6 @@ function update_domains {
97 97
 	fi
98 98
 }
99 99
 
100
-function backup_database {
101
-	if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
102
-		echo $"No MariaDB password was given"
103
-		restart_site
104
-		exit 10
105
-	fi
106
-	if [ ! -d $USB_MOUNT/backup/${1} ]; then
107
-		mkdir -p $USB_MOUNT/backup/${1}
108
-	fi
109
-	if [ ! -d $USB_MOUNT/backup/${1}data ]; then
110
-		mkdir -p $USB_MOUNT/backup/${1}data
111
-	fi
112
-	if [ ! -d /root/temp${1}data ]; then
113
-		mkdir -p /root/temp${1}data
114
-	fi
115
-	echo $"Obtaining ${1} database backup"
116
-	mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > /root/temp${1}data/${1}.sql
117
-	if [ ! -s /root/temp${1}data/${1}.sql ]; then
118
-		echo $"${1} database could not be saved"
119
-		shred -zu /root/temp${1}data/*
120
-		rm -rf /root/temp${1}data
121
-		umount $USB_MOUNT
122
-		rm -rf $USB_MOUNT
123
-		restart_site
124
-		exit 5
125
-	fi
126
-}
127
-
128
-function backup_directory_to_usb {
129
-	if [ ! -d ${1} ]; then
130
-		echo $"WARNING: directory does not exist: ${1}"
131
-	else
132
-		BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
133
-		if [ ! "$?" = "0" ]; then
134
-			echo $"Backup key could not be found"
135
-			restart_site
136
-			exit 6
137
-		fi
138
-		MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
139
-		if [ ! -d $USB_MOUNT/backup/${2} ]; then
140
-			mkdir -p $USB_MOUNT/backup/${2}
141
-		fi
142
-		obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
143
-		obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
144
-		if [[ $ENABLE_BACKUP_VERIFICATION == "yes" ]]; then
145
-			obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
146
-			if [ ! "$?" = "0" ]; then
147
-				umount $USB_MOUNT
148
-				rm -rf $USB_MOUNT
149
-				if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
150
-					shred -zu ${1}/*
151
-					rm -rf ${1}
152
-				fi
153
-				restart_site
154
-				exit 71
155
-			fi
156
-		fi
157
-		obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
158
-		if [ ! "$?" = "0" ]; then
159
-			umount $USB_MOUNT
160
-			rm -rf $USB_MOUNT
161
-			if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
162
-				shred -zu ${1}/*
163
-				rm -rf ${1}
164
-			fi
165
-			restart_site
166
-			exit 7
167
-		fi
168
-		if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
169
-			shred -zu ${1}/*
170
-			rm -rf ${1}
171
-		fi
172
-	fi
173
-}
174
-
175 100
 function make_backup_directory {
176 101
 	# make a backup directory on the drive
177 102
 	if [ ! -d $USB_MOUNT/backup ]; then
@@ -245,6 +170,15 @@ function backup_users {
245 170
 				fi
246 171
 			fi
247 172
 
173
+			# Backup emacs
174
+			if [ -d /home/$USERNAME/.emacs.d ]; then
175
+				echo $"Backing up Emacs config for $USERNAME"
176
+				if [ -f /home/$USERNAME/.emacs ]; then
177
+					cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
178
+				fi
179
+				backup_directory_to_usb /home/$USERNAME/.emacs.d config/$USERNAME
180
+			fi
181
+
248 182
 			# Backup user configs
249 183
 			if [ -d /home/$USERNAME/.config ]; then
250 184
 				echo $"Backing up config files for $USERNAME"
@@ -369,7 +303,7 @@ function backup_directories {
369 303
 		if [[ $required_directory != "none" ]]; then
370 304
 			if [ -d $required_directory ]; then
371 305
 				if [[ $database_name != "none" ]]; then
372
-					backup_database $database_name
306
+					backup_database_local $database_name
373 307
 				fi
374 308
 			fi
375 309
 		fi

+ 29
- 0
src/freedombone-restore-local Ver arquivo

@@ -609,6 +609,34 @@ function restore_user_config {
609 609
 	fi
610 610
 }
611 611
 
612
+function restore_user_emacs {
613
+	if [[ $RESTORE_APP != 'all' ]]; then
614
+		if [[ $RESTORE_APP != 'useremacs' ]]; then
615
+			return
616
+		fi
617
+	fi
618
+	if [ -d $USB_MOUNT/backup/emacs ]; then
619
+		for d in $USB_MOUNT/backup/emacs/*/ ; do
620
+			USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
621
+			if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
622
+				if [ ! -d /home/$USERNAME ]; then
623
+					${PROJECT_NAME}-adduser $USERNAME
624
+				fi
625
+				echo $"Restoring Emacs config for $USERNAME"
626
+				restore_directory_from_usb /root/tempemacs emacs/$USERNAME
627
+				cp -r /root/tempemacs/home/$USERNAME/.emacs.d /home/$USERNAME/
628
+				if [ ! "$?" = "0" ]; then
629
+					rm -rf /root/tempemacs
630
+					unmount_drive
631
+					exit 664
632
+				fi
633
+				cp -f /root/tempemacs/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
634
+				rm -rf /root/tempemacs
635
+			fi
636
+		done
637
+	fi
638
+}
639
+
612 640
 function gpg_pubkey_from_email {
613 641
 	key_owner_username=$1
614 642
 	key_email_address=$2
@@ -1264,6 +1292,7 @@ restore_admin_readme
1264 1292
 restore_ipfs
1265 1293
 restore_user_ssh_keys
1266 1294
 restore_user_config
1295
+restore_user_emacs
1267 1296
 restore_user_monkeysphere
1268 1297
 restore_user_fin
1269 1298
 restore_user_local

+ 99
- 0
src/freedombone-utils-backup Ver arquivo

@@ -28,6 +28,26 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
+# whether a given site is being suspended during backup
32
+SUSPENDED_SITE=
33
+
34
+function suspend_site {
35
+	# suspends a given website
36
+	SUSPENDED_SITE="$1"
37
+	nginx_dissite $SUSPENDED_SITE
38
+	service nginx reload
39
+}
40
+
41
+function restart_site {
42
+	# restarts a given website
43
+	if [ ! $SUSPENDED_SITE ]; then
44
+		return
45
+	fi
46
+	nginx_ensite $SUSPENDED_SITE
47
+	service nginx reload
48
+	SUSPENDED_SITE=
49
+}
50
+
31 51
 function configure_backup_key {
32 52
 	if grep -Fxq "configure_backup_key" $COMPLETION_FILE; then
33 53
 		return
@@ -162,4 +182,83 @@ function backup_unmount_drive {
162 182
 	echo $"Backup to USB drive is complete. You can now unplug it."
163 183
 }
164 184
 
185
+function backup_database_local {
186
+	if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
187
+		echo $"No MariaDB password was given"
188
+		function_check restart_site
189
+		restart_site
190
+		exit 10
191
+	fi
192
+	if [ ! -d $USB_MOUNT/backup/${1} ]; then
193
+		mkdir -p $USB_MOUNT/backup/${1}
194
+	fi
195
+	if [ ! -d $USB_MOUNT/backup/${1}data ]; then
196
+		mkdir -p $USB_MOUNT/backup/${1}data
197
+	fi
198
+	if [ ! -d /root/temp${1}data ]; then
199
+		mkdir -p /root/temp${1}data
200
+	fi
201
+	echo $"Obtaining ${1} database backup"
202
+	mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > /root/temp${1}data/${1}.sql
203
+	if [ ! -s /root/temp${1}data/${1}.sql ]; then
204
+		echo $"${1} database could not be saved"
205
+		shred -zu /root/temp${1}data/*
206
+		rm -rf /root/temp${1}data
207
+		umount $USB_MOUNT
208
+		rm -rf $USB_MOUNT
209
+		restart_site
210
+		exit 6835872
211
+	fi
212
+}
213
+
214
+function backup_directory_to_usb {
215
+	if [ ! -d ${1} ]; then
216
+		echo $"WARNING: directory does not exist: ${1}"
217
+	else
218
+		BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
219
+		if [ ! "$?" = "0" ]; then
220
+			echo $"Backup key could not be found"
221
+			function_check restart_site
222
+			restart_site
223
+			exit 6
224
+		fi
225
+		MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
226
+		if [ ! -d $USB_MOUNT/backup/${2} ]; then
227
+			mkdir -p $USB_MOUNT/backup/${2}
228
+		fi
229
+		obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
230
+		obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
231
+		if [[ $ENABLE_BACKUP_VERIFICATION == "yes" ]]; then
232
+			obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
233
+			if [ ! "$?" = "0" ]; then
234
+				umount $USB_MOUNT
235
+				rm -rf $USB_MOUNT
236
+				if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
237
+					shred -zu ${1}/*
238
+					rm -rf ${1}
239
+				fi
240
+				function_check restart_site
241
+				restart_site
242
+				exit 683252
243
+			fi
244
+		fi
245
+		obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
246
+		if [ ! "$?" = "0" ]; then
247
+			umount $USB_MOUNT
248
+			rm -rf $USB_MOUNT
249
+			if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
250
+				shred -zu ${1}/*
251
+				rm -rf ${1}
252
+			fi
253
+			function_check restart_site
254
+			restart_site
255
+			exit 7
256
+		fi
257
+		if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
258
+			shred -zu ${1}/*
259
+			rm -rf ${1}
260
+		fi
261
+	fi
262
+}
263
+
165 264
 # NOTE: deliberately no exit 0

+ 0
- 20
src/freedombone-utils-web Ver arquivo

@@ -53,9 +53,6 @@ MAX_PHP_MEMORY=64
53 53
 # logging level for Nginx
54 54
 WEBSERVER_LOG_LEVEL='warn'
55 55
 
56
-# whether a given site is being suspended during backup
57
-SUSPENDED_SITE=
58
-
59 56
 # test a domain name to see if it's valid
60 57
 function validate_domain_name {
61 58
 	# count the number of dots in the domain name
@@ -551,21 +548,4 @@ function install_command_line_browser {
551 548
 	echo 'install_command_line_browser' >> $COMPLETION_FILE
552 549
 }
553 550
 
554
-function suspend_site {
555
-	# suspends a given website
556
-	SUSPENDED_SITE="$1"
557
-	nginx_dissite $SUSPENDED_SITE
558
-	service nginx reload
559
-}
560
-
561
-function restart_site {
562
-	# restarts a given website
563
-	if [ ! $SUSPENDED_SITE ]; then
564
-		return
565
-	fi
566
-	nginx_ensite $SUSPENDED_SITE
567
-	service nginx reload
568
-	SUSPENDED_SITE=
569
-}
570
-
571 551
 # NOTE: deliberately no exit 0