瀏覽代碼

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

Bob Mottram 9 年之前
父節點
當前提交
a8ae880ccd
共有 4 個檔案被更改,包括 106 行新增2 行删除
  1. 41
    1
      src/freedombone-backup-local
  2. 41
    1
      src/freedombone-backup-remote
  3. 12
    0
      src/freedombone-restore-local
  4. 12
    0
      src/freedombone-restore-remote

+ 41
- 1
src/freedombone-backup-local 查看文件

@@ -368,6 +368,9 @@ function backup_configuration {
368 368
     fi
369 369
     cp -f $CONFIG_FILE /root/tempbackupconfig
370 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 374
     backup_directory_to_usb /root/tempbackupconfig config
372 375
 }
373 376
 
@@ -414,6 +417,38 @@ function backup_mariadb {
414 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 452
 function backup_extra_directories {
418 453
     if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
419 454
         return
@@ -425,7 +460,12 @@ function backup_extra_directories {
425 460
         backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
426 461
         if [ -d "$backup_dir" ]; then
427 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 469
         else
430 470
             echo $"WARNING: Directory $backup_dir does not exist"
431 471
         fi

+ 41
- 1
src/freedombone-backup-remote 查看文件

@@ -127,6 +127,9 @@ function backup_configuration {
127 127
     fi
128 128
     cp -f $CONFIG_FILE /root/tempbackupconfig
129 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 133
     backup_directory_to_friend /root/tempbackupconfig config
131 134
 }
132 135
 
@@ -439,6 +442,38 @@ function disperse_key_shares {
439 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 477
 function backup_extra_directories {
443 478
     if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
444 479
         return
@@ -450,7 +485,12 @@ function backup_extra_directories {
450 485
         backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
451 486
         if [ -d "$backup_dir" ]; then
452 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 494
         else
455 495
             echo $"WARNING: Directory $backup_dir does not exist"
456 496
         fi

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

@@ -232,6 +232,7 @@ function restore_configuration {
232 232
     if [ -d $USB_MOUNT/backup/config ]; then
233 233
         echo $"Restoring configuration files"
234 234
         restore_directory_from_usb /root/tempconfig config
235
+
235 236
         cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE
236 237
         if [ ! "$?" = "0" ]; then
237 238
             unmount_drive
@@ -242,12 +243,23 @@ function restore_configuration {
242 243
             # install according to the config file
243 244
             freedombone -c $CONFIG_FILE
244 245
         fi
246
+
245 247
         cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
246 248
         if [ ! "$?" = "0" ]; then
247 249
             unmount_drive
248 250
             rm -rf /root/tempconfig
249 251
             exit 6382
250 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 263
         rm -rf /root/tempconfig
252 264
     fi
253 265
 }

+ 12
- 0
src/freedombone-restore-remote 查看文件

@@ -142,6 +142,7 @@ function restore_configuration {
142 142
     if [ -d $SERVER_DIRECTORY/backup/config ]; then
143 143
         echo $"Restoring configuration files"
144 144
         restore_directory_from_friend /root/tempconfig config
145
+
145 146
         cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE
146 147
         if [ ! "$?" = "0" ]; then
147 148
             unmount_drive
@@ -152,12 +153,23 @@ function restore_configuration {
152 153
             # install according to the config file
153 154
             freedombone -c $CONFIG_FILE
154 155
         fi
156
+
155 157
         cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE
156 158
         if [ ! "$?" = "0" ]; then
157 159
             unmount_drive
158 160
             rm -rf /root/tempconfig
159 161
             exit 7252
160 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 173
         rm -rf /root/tempconfig
162 174
     fi
163 175
 }