Parcourir la source

More tidying of backup command

Bob Mottram il y a 9 ans
Parent
révision
0ecc504bb6
1 fichiers modifiés avec 55 ajouts et 82 suppressions
  1. 55
    82
      src/freedombone-backup-local

+ 55
- 82
src/freedombone-backup-local Voir le fichier

@@ -45,6 +45,19 @@ if [ -f /root/dbpass ]; then
45 45
     DATABASE_PASSWORD=$(cat /root/dbpass)
46 46
 fi
47 47
 
48
+MICROBLOG_DOMAIN_NAME='microblog'
49
+if grep -q "GNU Social domain" $COMPLETION_FILE; then
50
+    MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
51
+fi
52
+HUBZILLA_DOMAIN_NAME='hubzilla'
53
+if grep -q "Hubzilla domain" $COMPLETION_FILE; then
54
+    HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
55
+fi
56
+FULLBLOG_DOMAIN_NAME='blog'
57
+if grep -q "Blog domain" $COMPLETION_FILE; then
58
+    FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
59
+fi
60
+
48 61
 function mount_drive {
49 62
     if [ $1 ]; then
50 63
         USB_DRIVE=/dev/${1}1
@@ -263,22 +276,47 @@ function backup_users {
263 276
 function backup_directories {
264 277
     # directories to be backed up (source,dest)
265 278
     backup_dirs=(
266
-        "/etc/letsencrypt,            letsencrypt"
267
-        "/var/lib/dokuwiki,           wiki"
268
-        "/etc/dokuwiki,               wiki2"
269
-        "/etc/ssl,                    ssl"
270
-        "/var/spool/mlmmj,            mailinglist"
271
-        "/var/lib/prosody,            xmpp"
272
-        "/etc/nginx/sites-available,  web"
273
-        "/home/$ADMIN_USERNAME/.ipfs, ipfs"
274
-        "/var/cache/minidlna,         dlna"
279
+        "none,                               none,       /etc/letsencrypt,                                letsencrypt"
280
+        "none,                               none,       /var/lib/dokuwiki,                               wiki"
281
+        "none,                               none,       /etc/dokuwiki,                                   wiki2"
282
+        "none,                               none,       /etc/ssl,                                        ssl"
283
+        "none,                               none,       /var/spool/mlmmj,                                mailinglist"
284
+        "none,                               none,       /var/lib/prosody,                                xmpp"
285
+        "none,                               none,       /etc/nginx/sites-available,                      web"
286
+        "none,                               none,       /home/$ADMIN_USERNAME/.ipfs,                     ipfs"
287
+        "none,                               none,       /var/cache/minidlna,                             dlna"
288
+        "/etc/owncloud,                      owncloud,   /root/tempownclouddata,                          ownclouddata"
289
+        "none,                               none,       /var/lib/owncloud,                               owncloud"
290
+        "none,                               none,       /etc/owncloud,                                   owncloud2"
291
+        "/home/git/go/src/github.com/gogits, gogs,       /root/tempgogsdata,                              gogsdata"
292
+        "none,                               none,       /home/git/go/src/github.com/gogits/gogs/custom,  gogs"
293
+        "none,                               none,       /home/git/gogs-repositories,                     gogsrepos"
294
+        "none,                               none,       /home/git/.ssh,                                  gogsssh"
295
+        "none,                               none,       /var/lib/tox-bootstrapd,                         tox"
296
+        "/var/www/${MICROBLOG_DOMAIN_NAME},  gnusocial,  /root/tempgnusocialdata,                         gnusocialdata"
297
+        "none,                               none,       /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs,        gnusocial"
298
+        "/var/www/${HUBZILLA_DOMAIN_NAME},   hubzilla,   /root/temphubzilladata,                          hubzilladata"
299
+        "none,                               none,       /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs,         hubzilla"
300
+        "none,                               none,       /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs,         blog"
275 301
     )
276 302
 
277 303
     for dr in "${backup_dirs[@]}"
278 304
     do
279
-        source_directory=$(echo $dr | awk -F ',' '{print $1}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
305
+        # if this directory exists then backup the given database
306
+        required_directory=$(echo $dr | awk -F ',' '{print $1}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
307
+        if [[ $required_directory != "none" ]]; then
308
+            if [ -d $required_directory ]; then
309
+                database_name=$(echo $dr | awk -F ',' '{print $2}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
310
+                if [[ $database_name != "none" ]]; then
311
+                    backup_database $database_name
312
+                fi
313
+            fi
314
+        fi
315
+
316
+        # if this directory exists then back it up to the given destination
317
+        source_directory=$(echo $dr | awk -F ',' '{print $3}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
280 318
         if [ -d $source_directory ]; then
281
-            dest_directory=$(echo $dr | awk -F ',' '{print $2}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
319
+            dest_directory=$(echo $dr | awk -F ',' '{print $4}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
282 320
             echo $"Backing up $source_directory to $dest_directory"
283 321
             backup_directory_to_usb $source_directory $dest_directory
284 322
         fi
@@ -289,74 +327,19 @@ mount_drive $1 $2
289 327
 make_backup_directory
290 328
 check_storage_space_remaining
291 329
 backup_users
292
-backup_directories
293
-
294
-# backup gnusocial
295
-if grep -q "GNU Social domain" $COMPLETION_FILE; then
296
-    MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
297
-    if [ -d /var/www/${MICROBLOG_DOMAIN_NAME} ]; then
298
-        backup_database gnusocial
299
-        backup_directory_to_usb /root/tempgnusocialdata gnusocialdata
300
-        echo $"Backing up GNU social installation"
301
-        backup_directory_to_usb /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs gnusocial
302
-    else
303
-        echo $"GNU Social domain specified but not found in /var/www/${MICROBLOG_DOMAIN_NAME}"
304
-        exit 6327
305
-    fi
306
-fi
307
-
308
-# backup hubzilla
309
-if grep -q "Hubzilla domain" $COMPLETION_FILE; then
310
-    HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
311
-    if [ -d /var/www/${HUBZILLA_DOMAIN_NAME} ]; then
312
-        backup_database hubzilla
313
-        backup_directory_to_usb /root/temphubzilladata hubzilladata
314
-        echo $"Backing up Hubzilla installation"
315
-        backup_directory_to_usb /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs hubzilla
316
-    else
317
-        echo $"Hubzilla domain specified but not found in /var/www/${HUBZILLA_DOMAIN_NAME}"
318
-        exit 2578
319
-    fi
320
-fi
321
-
322
-# backup owncloud
323
-if [ -d /etc/owncloud ]; then
324
-    if [ ! -d $USB_MOUNT/backup/owncloud2 ]; then
325
-        mkdir -p $USB_MOUNT/backup/owncloud2
326
-    fi
327
-    backup_database owncloud
328
-    backup_directory_to_usb /root/tempownclouddata ownclouddata
329
-    echo $"Obtaining Owncloud data backup"
330
-    backup_directory_to_usb /var/lib/owncloud owncloud
331
-    backup_directory_to_usb /etc/owncloud owncloud2
332
-fi
333 330
 
334
-# backup gogs
335 331
 if [ -d /home/git/go/src/github.com/gogits ]; then
336
-    backup_database gogs
337
-    backup_directory_to_usb /root/tempgogsdata gogsdata
338
-    echo $"Obtaining Gogs settings backup"
339
-    backup_directory_to_usb /home/git/go/src/github.com/gogits/gogs/custom gogs
340
-    echo $"Obtaining Gogs repos backup"
341 332
     mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME
342
-    backup_directory_to_usb /home/git/gogs-repositories gogsrepos
343
-    echo $"Obtaining Gogs authorized_keys backup"
344
-    backup_directory_to_usb /home/git/.ssh gogsssh
345 333
 fi
346
-
347
-# Backup blog
348
-if grep -q "Blog domain" $COMPLETION_FILE; then
349
-    FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
350
-    if [ -d /var/www/${FULLBLOG_DOMAIN_NAME} ]; then
351
-        echo $"Obtaining blog backup"
352
-        backup_directory_to_usb /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs blog
353
-    else
354
-        echo $"Blog domain specified but not found in /var/www/${FULLBLOG_DOMAIN_NAME}"
355
-        exit 2578
356
-    fi
334
+if [ -d /var/lib/tox-bootstrapd ]; then
335
+    cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
336
+    if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
337
+        rm -rf /var/lib/tox-bootstrapd/Maildir
357 338
     fi
358 339
 fi
359 340
 
341
+backup_directories
342
+
360 343
 # Backup admin user README file
361 344
 if [ -f /home/$ADMIN_USERNAME/README ]; then
362 345
     echo $"Backing up README"
@@ -397,16 +380,6 @@ if [ ${#DATABASE_PASSWORD} -gt 1 ]; then
397 380
     backup_directory_to_usb /root/tempmariadb mariadb
398 381
 fi
399 382
 
400
-# Backup Tox node settings
401
-if [ -d /var/lib/tox-bootstrapd ]; then
402
-    echo $"Backing up Tox node settings"
403
-    cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
404
-    if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
405
-        rm -rf /var/lib/tox-bootstrapd/Maildir
406
-    fi
407
-    backup_directory_to_usb /var/lib/tox-bootstrapd tox
408
-fi
409
-
410 383
 unmount_drive
411 384
 
412 385
 exit 0