Browse Source

Check that any extra directories being backed up are not the same as existing ones

Bob Mottram 9 years ago
parent
commit
a8ae880ccd

+ 41
- 1
src/freedombone-backup-local View File

368
     fi
368
     fi
369
     cp -f $CONFIG_FILE /root/tempbackupconfig
369
     cp -f $CONFIG_FILE /root/tempbackupconfig
370
     cp -f $COMPLETION_FILE /root/tempbackupconfig
370
     cp -f $COMPLETION_FILE /root/tempbackupconfig
371
+    if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
372
+        cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig
373
+    fi
371
     backup_directory_to_usb /root/tempbackupconfig config
374
     backup_directory_to_usb /root/tempbackupconfig config
372
 }
375
 }
373
 
376
 
414
     fi
417
     fi
415
 }
418
 }
416
 
419
 
420
+function valid_backup_destination {
421
+    destination_dir="$1"
422
+    is_valid="yes"
423
+
424
+    if [[ "$destination_dir" == "hubzilla" || \
425
+          "$destination_dir" == "hubzilladata" || \
426
+          "$destination_dir" == "gogs" || \
427
+          "$destination_dir" == "gogsrepos" || \
428
+          "$destination_dir" == "gogsssh" || \
429
+          "$destination_dir" == "gnusocial" || \
430
+          "$destination_dir" == "gnusocialdata" || \
431
+          "$destination_dir" == "mariadb" || \
432
+          "$destination_dir" == "config" || \
433
+          "$destination_dir" == "letsencrypt" || \
434
+          "$destination_dir" == "wiki" || \
435
+          "$destination_dir" == "wiki2" || \
436
+          "$destination_dir" == "xmpp" || \
437
+          "$destination_dir" == "ipfs" || \
438
+          "$destination_dir" == "dlna" || \
439
+          "$destination_dir" == "tox" || \
440
+          "$destination_dir" == "ssl" || \
441
+          "$destination_dir" == "blog" || \
442
+          "$destination_dir" == "owncloud" || \
443
+          "$destination_dir" == "owncloud2" || \
444
+          "$destination_dir" == "ownclouddata" || \
445
+          "$destination_dir" == "mailinglist" ]]; then
446
+        is_valid="no"
447
+    fi
448
+
449
+    echo $is_valid
450
+}
451
+
417
 function backup_extra_directories {
452
 function backup_extra_directories {
418
     if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
453
     if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
419
         return
454
         return
425
         backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
460
         backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
426
         if [ -d "$backup_dir" ]; then
461
         if [ -d "$backup_dir" ]; then
427
             destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
462
             destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
428
-            backup_directory_to_usb "$backup_dir" "$destination_dir"
463
+            if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
464
+                backup_directory_to_usb "$backup_dir" "$destination_dir"
465
+            else
466
+                echo $"WARNING: The backup directory $destination_dir is already used."
467
+                echo $"Choose a different destination name for backing up $backup_dir"
468
+            fi
429
         else
469
         else
430
             echo $"WARNING: Directory $backup_dir does not exist"
470
             echo $"WARNING: Directory $backup_dir does not exist"
431
         fi
471
         fi

+ 41
- 1
src/freedombone-backup-remote View File

127
     fi
127
     fi
128
     cp -f $CONFIG_FILE /root/tempbackupconfig
128
     cp -f $CONFIG_FILE /root/tempbackupconfig
129
     cp -f $COMPLETION_FILE /root/tempbackupconfig
129
     cp -f $COMPLETION_FILE /root/tempbackupconfig
130
+	if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
131
+		cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig
132
+	fi
130
     backup_directory_to_friend /root/tempbackupconfig config
133
     backup_directory_to_friend /root/tempbackupconfig config
131
 }
134
 }
132
 
135
 
439
     fi
442
     fi
440
 }
443
 }
441
 
444
 
445
+function valid_backup_destination {
446
+    destination_dir="$1"
447
+    is_valid="yes"
448
+
449
+    if [[ "$destination_dir" == "hubzilla" || \
450
+          "$destination_dir" == "hubzilladata" || \
451
+          "$destination_dir" == "gogs" || \
452
+          "$destination_dir" == "gogsrepos" || \
453
+          "$destination_dir" == "gogsssh" || \
454
+          "$destination_dir" == "gnusocial" || \
455
+          "$destination_dir" == "gnusocialdata" || \
456
+          "$destination_dir" == "mariadb" || \
457
+          "$destination_dir" == "config" || \
458
+          "$destination_dir" == "letsencrypt" || \
459
+          "$destination_dir" == "wiki" || \
460
+          "$destination_dir" == "wiki2" || \
461
+          "$destination_dir" == "xmpp" || \
462
+          "$destination_dir" == "ipfs" || \
463
+          "$destination_dir" == "dlna" || \
464
+          "$destination_dir" == "tox" || \
465
+          "$destination_dir" == "ssl" || \
466
+          "$destination_dir" == "blog" || \
467
+          "$destination_dir" == "owncloud" || \
468
+          "$destination_dir" == "owncloud2" || \
469
+          "$destination_dir" == "ownclouddata" || \
470
+          "$destination_dir" == "mailinglist" ]]; then
471
+        is_valid="no"
472
+    fi
473
+
474
+    echo $is_valid
475
+}
476
+
442
 function backup_extra_directories {
477
 function backup_extra_directories {
443
     if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
478
     if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
444
         return
479
         return
450
         backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
485
         backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
451
         if [ -d "$backup_dir" ]; then
486
         if [ -d "$backup_dir" ]; then
452
             destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
487
             destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
453
-            backup_directory_to_friend "$backup_dir" "$destination_dir"
488
+            if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
489
+				backup_directory_to_friend "$backup_dir" "$destination_dir"
490
+            else
491
+                echo $"WARNING: The backup directory $destination_dir is already used."
492
+                echo $"Choose a different destination name for backing up $backup_dir"
493
+            fi
454
         else
494
         else
455
             echo $"WARNING: Directory $backup_dir does not exist"
495
             echo $"WARNING: Directory $backup_dir does not exist"
456
         fi
496
         fi

+ 12
- 0
src/freedombone-restore-local View File

232
     if [ -d $USB_MOUNT/backup/config ]; then
232
     if [ -d $USB_MOUNT/backup/config ]; then
233
         echo $"Restoring configuration files"
233
         echo $"Restoring configuration files"
234
         restore_directory_from_usb /root/tempconfig config
234
         restore_directory_from_usb /root/tempconfig config
235
+
235
         cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE
236
         cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE
236
         if [ ! "$?" = "0" ]; then
237
         if [ ! "$?" = "0" ]; then
237
             unmount_drive
238
             unmount_drive
242
             # install according to the config file
243
             # install according to the config file
243
             freedombone -c $CONFIG_FILE
244
             freedombone -c $CONFIG_FILE
244
         fi
245
         fi
246
+
245
         cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
247
         cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
246
         if [ ! "$?" = "0" ]; then
248
         if [ ! "$?" = "0" ]; then
247
             unmount_drive
249
             unmount_drive
248
             rm -rf /root/tempconfig
250
             rm -rf /root/tempconfig
249
             exit 6382
251
             exit 6382
250
         fi
252
         fi
253
+
254
+        if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then
255
+            cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES}
256
+            if [ ! "$?" = "0" ]; then
257
+                unmount_drive
258
+                rm -rf /root/tempconfig
259
+                exit 62121
260
+            fi
261
+        fi
262
+
251
         rm -rf /root/tempconfig
263
         rm -rf /root/tempconfig
252
     fi
264
     fi
253
 }
265
 }

+ 12
- 0
src/freedombone-restore-remote View File

142
     if [ -d $SERVER_DIRECTORY/backup/config ]; then
142
     if [ -d $SERVER_DIRECTORY/backup/config ]; then
143
         echo $"Restoring configuration files"
143
         echo $"Restoring configuration files"
144
         restore_directory_from_friend /root/tempconfig config
144
         restore_directory_from_friend /root/tempconfig config
145
+
145
         cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE
146
         cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE
146
         if [ ! "$?" = "0" ]; then
147
         if [ ! "$?" = "0" ]; then
147
             unmount_drive
148
             unmount_drive
152
             # install according to the config file
153
             # install according to the config file
153
             freedombone -c $CONFIG_FILE
154
             freedombone -c $CONFIG_FILE
154
         fi
155
         fi
156
+
155
         cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
157
         cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
156
         if [ ! "$?" = "0" ]; then
158
         if [ ! "$?" = "0" ]; then
157
             unmount_drive
159
             unmount_drive
158
             rm -rf /root/tempconfig
160
             rm -rf /root/tempconfig
159
             exit 7252
161
             exit 7252
160
         fi
162
         fi
163
+
164
+        if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then
165
+            cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES}
166
+            if [ ! "$?" = "0" ]; then
167
+                unmount_drive
168
+                rm -rf /root/tempconfig
169
+                exit 62121
170
+            fi
171
+        fi
172
+
161
         rm -rf /root/tempconfig
173
         rm -rf /root/tempconfig
162
     fi
174
     fi
163
 }
175
 }