Selaa lähdekoodia

Tidying of backups

Bob Mottram 8 vuotta sitten
vanhempi
commit
cfa5f4832e
3 muutettua tiedostoa jossa 67 lisäystä ja 147 poistoa
  1. 11
    89
      src/freedombone-backup-local
  2. 10
    58
      src/freedombone-backup-remote
  3. 46
    0
      src/freedombone-utils-backup

+ 11
- 89
src/freedombone-backup-local Näytä tiedosto

@@ -30,12 +30,20 @@
30 30
 
31 31
 PROJECT_NAME='freedombone'
32 32
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
33
+CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
33 34
 BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
34 35
 ENABLE_BACKUP_VERIFICATION="no"
35 36
 
36 37
 export TEXTDOMAIN=${PROJECT_NAME}-backup-local
37 38
 export TEXTDOMAINDIR="/usr/share/locale"
38 39
 
40
+PROJECT_INSTALL_DIR=/usr/local/bin
41
+if [ -f /usr/bin/${PROJECT_NAME} ]; then
42
+    PROJECT_INSTALL_DIR=/usr/bin
43
+fi
44
+
45
+source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
46
+
39 47
 # include utils which allow function_check and drive mount
40 48
 UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
41 49
 for f in $UTILS_FILES
@@ -46,17 +54,7 @@ done
46 54
 USB_DRIVE=/dev/sdb1
47 55
 USB_MOUNT=/mnt/usb
48 56
 
49
-# get default USB from config file
50
-CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
51
-if [ -f $CONFIG_FILE ]; then
52
-    if grep -q "USB_DRIVE=" $CONFIG_FILE; then
53
-        USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
54
-    fi
55
-fi
56
-
57
-# get the version of Go being used
58
-GO_VERSION=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
59
-GVM_HOME=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GVM_HOME=' | head -n 1 | awk -F '=' '{print $2}')
57
+read_config_param USB_DRIVE
60 58
 
61 59
 ADMIN_USERNAME=
62 60
 ADMIN_NAME=
@@ -199,14 +197,6 @@ function backup_users {
199 197
 }
200 198
 
201 199
 function backup_directories {
202
-    export GVM_ROOT=$GVM_HOME
203
-    if [ -d $GVM_ROOT/bin ]; then
204
-        cd $GVM_ROOT/bin
205
-        [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
206
-        gvm use go${GO_VERSION} --default
207
-        systemctl set-environment GOPATH=$GOPATH
208
-    fi
209
-
210 200
     # directories to be backed up (source,dest)
211 201
     backup_dirs=(
212 202
         "/etc/letsencrypt,                      letsencrypt"
@@ -244,18 +234,7 @@ function remove_backup_directory {
244 234
 }
245 235
 
246 236
 function prepare_directories {
247
-    export GVM_ROOT=$GVM_HOME
248
-    if [ -d $GVM_ROOT/bin ]; then
249
-        cd $GVM_ROOT/bin
250
-        [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
251
-        gvm use go${GO_VERSION} --default
252
-        systemctl set-environment GOPATH=$GOPATH
253
-    fi
254
-
255 237
     # Some miscellaneous preparation for backing up directories
256
-    if [ -d $GOPATH/src/github.com/gogits ]; then
257
-        mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME
258
-    fi
259 238
     if [ -d /var/lib/tox-bootstrapd ]; then
260 239
         cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
261 240
         if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
@@ -270,7 +249,7 @@ function backup_configuration {
270 249
     if [ ! -d $temp_backup_dir ]; then
271 250
         mkdir -p $temp_backup_dir
272 251
     fi
273
-    cp -f $CONFIG_FILE $temp_backup_dir
252
+    cp -f $CONFIGURATION_FILE $temp_backup_dir
274 253
     cp -f $COMPLETION_FILE $temp_backup_dir
275 254
     if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
276 255
         cp -f $BACKUP_EXTRA_DIRECTORIES $temp_backup_dir
@@ -314,63 +293,6 @@ function backup_mariadb {
314 293
     fi
315 294
 }
316 295
 
317
-function valid_backup_destination {
318
-    destination_dir="$1"
319
-    is_valid="yes"
320
-
321
-    if [[ "$destination_dir" == "hubzilla" || \
322
-                "$destination_dir" == "hubzilladata" || \
323
-                "$destination_dir" == "gogs" || \
324
-                "$destination_dir" == "gogsrepos" || \
325
-                "$destination_dir" == "gogsssh" || \
326
-                "$destination_dir" == "gnusocial" || \
327
-                "$destination_dir" == "gnusocialdata" || \
328
-                "$destination_dir" == "mariadb" || \
329
-                "$destination_dir" == "config" || \
330
-                "$destination_dir" == "letsencrypt" || \
331
-                "$destination_dir" == "wiki" || \
332
-                "$destination_dir" == "wiki2" || \
333
-                "$destination_dir" == "xmpp" || \
334
-                "$destination_dir" == "ipfs" || \
335
-                "$destination_dir" == "dlna" || \
336
-                "$destination_dir" == "tox" || \
337
-                "$destination_dir" == "ssl" || \
338
-                "$destination_dir" == "ttrss" || \
339
-                "$destination_dir" == "blog" || \
340
-                "$destination_dir" == "syncthingconfig" || \
341
-                "$destination_dir" == "syncthingshared" || \
342
-                "$destination_dir" == "syncthing" || \
343
-                "$destination_dir" == "mediagoblin" || \
344
-                "$destination_dir" == "mailinglist" ]]; then
345
-        is_valid="no"
346
-    fi
347
-
348
-    echo $is_valid
349
-}
350
-
351
-function backup_extra_directories {
352
-    if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
353
-        return
354
-    fi
355
-
356
-    echo $"Backing up some additional directories"
357
-    while read backup_line
358
-    do
359
-        backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
360
-        if [ -d "$backup_dir" ]; then
361
-            destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
362
-            if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
363
-                backup_directory_to_usb "$backup_dir" "$destination_dir"
364
-            else
365
-                echo $"WARNING: The backup directory $destination_dir is already used."
366
-                echo $"Choose a different destination name for backing up $backup_dir"
367
-            fi
368
-        else
369
-            echo $"WARNING: Directory $backup_dir does not exist"
370
-        fi
371
-    done <$BACKUP_EXTRA_DIRECTORIES
372
-}
373
-
374 296
 # has the remove option been set ?
375 297
 remove_option=$2
376 298
 if [[ $1 == "remove" ]]; then
@@ -388,7 +310,7 @@ backup_apps local
388 310
 backup_configuration
389 311
 backup_admin_readme
390 312
 backup_mariadb
391
-backup_extra_directories
313
+backup_extra_directories local
392 314
 backup_unmount_drive $USB_DRIVE $USB_MOUNT
393 315
 echo $"Backup to USB drive is complete. You can now unplug it."
394 316
 

+ 10
- 58
src/freedombone-backup-remote Näytä tiedosto

@@ -30,13 +30,20 @@
30 30
 
31 31
 PROJECT_NAME='freedombone'
32 32
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
33
-CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
33
+CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
34 34
 BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
35 35
 ENABLE_VERIFICATION="no"
36 36
 
37 37
 export TEXTDOMAIN=${PROJECT_NAME}-backup-remote
38 38
 export TEXTDOMAINDIR="/usr/share/locale"
39 39
 
40
+PROJECT_INSTALL_DIR=/usr/local/bin
41
+if [ -f /usr/bin/${PROJECT_NAME} ]; then
42
+    PROJECT_INSTALL_DIR=/usr/bin
43
+fi
44
+
45
+source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
46
+
40 47
 # utilities needed for backup commands
41 48
 UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
42 49
 for f in $UTILS_FILES
@@ -107,7 +114,7 @@ function backup_configuration {
107 114
     if [ ! -d $temp_backup_dir ]; then
108 115
         mkdir -p $temp_backup_dir
109 116
     fi
110
-    cp -f $CONFIG_FILE $temp_backup_dir
117
+    cp -f $CONFIGURATION_FILE $temp_backup_dir
111 118
     cp -f $COMPLETION_FILE $temp_backup_dir
112 119
     if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
113 120
         cp -f $BACKUP_EXTRA_DIRECTORIES $temp_backup_dir
@@ -357,61 +364,6 @@ function disperse_key_shares {
357 364
     fi
358 365
 }
359 366
 
360
-function valid_backup_destination {
361
-    destination_dir="$1"
362
-    is_valid="yes"
363
-
364
-    if [[ "$destination_dir" == "hubzilla" || \
365
-                "$destination_dir" == "hubzilladata" || \
366
-                "$destination_dir" == "gogs" || \
367
-                "$destination_dir" == "gogsrepos" || \
368
-                "$destination_dir" == "gogsssh" || \
369
-                "$destination_dir" == "gnusocial" || \
370
-                "$destination_dir" == "gnusocialdata" || \
371
-                "$destination_dir" == "mariadb" || \
372
-                "$destination_dir" == "config" || \
373
-                "$destination_dir" == "letsencrypt" || \
374
-                "$destination_dir" == "wiki" || \
375
-                "$destination_dir" == "wiki2" || \
376
-                "$destination_dir" == "xmpp" || \
377
-                "$destination_dir" == "ipfs" || \
378
-                "$destination_dir" == "dlna" || \
379
-                "$destination_dir" == "tox" || \
380
-                "$destination_dir" == "ssl" || \
381
-                "$destination_dir" == "blog" || \
382
-                "$destination_dir" == "syncthing" || \
383
-                "$destination_dir" == "syncthingconfig" || \
384
-                "$destination_dir" == "syncthingshared" || \
385
-                "$destination_dir" == "mailinglist" ]]; then
386
-        is_valid="no"
387
-    fi
388
-
389
-    echo $is_valid
390
-}
391
-
392
-function backup_extra_directories {
393
-    if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
394
-        return
395
-    fi
396
-
397
-    echo $"Backing up some additional directories"
398
-    while read backup_line
399
-    do
400
-        backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
401
-        if [ -d "$backup_dir" ]; then
402
-            destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
403
-            if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
404
-                backup_directory_to_friend "$backup_dir" "$destination_dir"
405
-            else
406
-                echo $"WARNING: The backup directory $destination_dir is already used."
407
-                echo $"Choose a different destination name for backing up $backup_dir"
408
-            fi
409
-        else
410
-            echo $"WARNING: Directory $backup_dir does not exist"
411
-        fi
412
-    done <$BACKUP_EXTRA_DIRECTORIES
413
-}
414
-
415 367
 TEST_MODE="no"
416 368
 if [[ "$1" == "test" ]]; then
417 369
     TEST_MODE="yes"
@@ -428,7 +380,7 @@ if [[ $TEST_MODE == "no" ]]; then
428 380
     backup_certs
429 381
     backup_mailing_list
430 382
     backup_apps remote
431
-    backup_extra_directories
383
+    backup_extra_directories remote
432 384
 fi
433 385
 
434 386
 # For each remote server

+ 46
- 0
src/freedombone-utils-backup Näytä tiedosto

@@ -505,4 +505,50 @@ function restore_database {
505 505
     fi
506 506
 }
507 507
 
508
+function valid_backup_destination {
509
+    # used to check whether any additional backup directories clash with
510
+    # exiting apps
511
+    destination_dir="$1"
512
+    is_valid="yes"
513
+
514
+    available_variants_list=()
515
+    available_system_variants
516
+
517
+    item_in_array "${destination_dir}" "${available_variants_list[@]}"
518
+    if [[ $? != 0 ]]; then
519
+        is_valid="no"
520
+    fi
521
+
522
+    echo $is_valid
523
+}
524
+
525
+function backup_extra_directories {
526
+    if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
527
+        return
528
+    fi
529
+
530
+    backup_type="$1"
531
+
532
+    echo $"Backing up some additional directories"
533
+    while read backup_line
534
+    do
535
+        backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
536
+        if [ -d "$backup_dir" ]; then
537
+            destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
538
+            if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
539
+                if [[ $backup_type == "local" ]]; then
540
+                    backup_directory_to_usb "$backup_dir" "$destination_dir"
541
+                else
542
+                    backup_directory_to_friend "$backup_dir" "$destination_dir"
543
+                fi
544
+            else
545
+                echo $"WARNING: The backup directory $destination_dir is already used."
546
+                echo $"Choose a different destination name for backing up $backup_dir"
547
+            fi
548
+        else
549
+            echo $"WARNING: Directory $backup_dir does not exist"
550
+        fi
551
+    done <$BACKUP_EXTRA_DIRECTORIES
552
+}
553
+
508 554
 # NOTE: deliberately no exit 0