Browse Source

Backup and restore of syncthing

Replacing owncloud
Bob Mottram 9 years ago
parent
commit
37b0fd0e12
4 changed files with 1079 additions and 991 deletions
  1. 257
    246
      src/freedombone-backup-local
  2. 31
    16
      src/freedombone-backup-remote
  3. 728
    698
      src/freedombone-restore-local
  4. 63
    31
      src/freedombone-restore-remote

+ 257
- 246
src/freedombone-backup-local View File

@@ -100,10 +100,6 @@ function update_domains {
100 100
     if grep -q "Blog domain" $COMPLETION_FILE; then
101 101
         FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
102 102
     fi
103
-    OWNCLOUD_DOMAIN_NAME='owncloud'
104
-    if grep -q "Owncloud domain" $COMPLETION_FILE; then
105
-        OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
106
-    fi
107 103
     MEDIAGOBLIN_DOMAIN_NAME='mediagoblin'
108 104
     if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
109 105
         MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
@@ -299,280 +295,295 @@ function backup_users {
299 295
                 backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME
300 296
             fi
301 297
 
302
-            # Backup user configs
303
-            if [ -d /home/$USERNAME/.config ]; then
304
-                echo $"Backing up config files for $USERNAME"
305
-                backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME
306
-            fi
307
-
308
-            # Backup user local
309
-            if [ -d /home/$USERNAME/.local ]; then
310
-                echo $"Backing up local files for $USERNAME"
311
-                backup_directory_to_usb /home/$USERNAME/.local local/$USERNAME
312
-            fi
313
-
314
-            # Backup mutt
315
-            if [ -f /home/$USERNAME/.muttrc ]; then
316
-                echo $"Backing up Mutt settings for $USERNAME"
317
-                if [ ! -d /home/$USERNAME/tempbackup ]; then
318
-                    mkdir -p /home/$USERNAME/tempbackup
319
-                fi
320
-                cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup
321
-                if [ -f /etc/Muttrc ]; then
322
-                    cp /etc/Muttrc /home/$USERNAME/tempbackup
323
-                fi
324
-                backup_directory_to_usb /home/$USERNAME/tempbackup mutt/$USERNAME
325
-            fi
326
-
327
-            # Backup email
328
-            if [ -d /home/$USERNAME/Maildir ]; then
329
-                echo $"Creating an email archive for $USERNAME"
330
-                if [ ! -d /root/tempbackupemail/$USERNAME ]; then
331
-                    mkdir -p /root/tempbackupemail/$USERNAME
332
-                fi
333
-                tar -czvf /root/tempbackupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir
334
-                echo $"Backing up emails for $USERNAME"
335
-                backup_directory_to_usb /root/tempbackupemail/$USERNAME mail/$USERNAME
336
-            fi
337
-
338
-            # Backup spamassassin
339
-            if [ -d /home/$USERNAME/.spamassassin ]; then
340
-                echo $"Backing up spamassassin settings for $USERNAME"
341
-                backup_directory_to_usb /home/$USERNAME/.spamassassin spamassassin/$USERNAME
342
-            fi
343
-
344
-            # Backup procmail
345
-            if [ -f /home/$USERNAME/.procmailrc ]; then
346
-                echo $"Backing up procmail settings for $USERNAME"
347
-                if [ ! -d /home/$USERNAME/tempbackup ]; then
348
-                    mkdir -p /home/$USERNAME/tempbackup
349
-                fi
350
-                cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup
351
-                backup_directory_to_usb /home/$USERNAME/tempbackup procmail/$USERNAME
352
-            fi
353
-        fi
354
-    done
298
+            # Backup syncthing
299
+            if [ -d /home/$USERNAME/Sync ]; then
300
+                echo $"Backing up syncthing files for $USERNAME"
301
+                backup_directory_to_usb /home/$USERNAME/Sync syncthing/$USERNAME
302
+				# ensure that device IDs will be backed up as part of user config settings
303
+				if [ ! -d /home/$USERNAME/.config/syncthing ]; then
304
+					mkdir -p /home/$USERNAME/.config/syncthing
305
+					chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
306
+				fi					
307
+				if [ -f /home/$USERNAME/.syncthing-server-id ]; then
308
+					cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
309
+					chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
310
+				fi				
311
+				if [ -f /home/$USERNAME/.syncthingids ]; then
312
+					cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
313
+					chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
314
+				fi				
315
+			fi
316
+			
317
+			# Backup user configs
318
+			if [ -d /home/$USERNAME/.config ]; then
319
+				echo $"Backing up config files for $USERNAME"
320
+				backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME
321
+			fi
322
+			
323
+			# Backup user local
324
+			if [ -d /home/$USERNAME/.local ]; then
325
+				echo $"Backing up local files for $USERNAME"
326
+				backup_directory_to_usb /home/$USERNAME/.local local/$USERNAME
327
+			fi
328
+
329
+			# Backup mutt
330
+			if [ -f /home/$USERNAME/.muttrc ]; then
331
+				echo $"Backing up Mutt settings for $USERNAME"
332
+				if [ ! -d /home/$USERNAME/tempbackup ]; then
333
+					mkdir -p /home/$USERNAME/tempbackup
334
+				fi
335
+				cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup
336
+				if [ -f /etc/Muttrc ]; then
337
+					cp /etc/Muttrc /home/$USERNAME/tempbackup
338
+				fi
339
+				backup_directory_to_usb /home/$USERNAME/tempbackup mutt/$USERNAME
340
+			fi
341
+
342
+			# Backup email
343
+			if [ -d /home/$USERNAME/Maildir ]; then
344
+				echo $"Creating an email archive for $USERNAME"
345
+				if [ ! -d /root/tempbackupemail/$USERNAME ]; then
346
+					mkdir -p /root/tempbackupemail/$USERNAME
347
+				fi
348
+				tar -czvf /root/tempbackupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir
349
+				echo $"Backing up emails for $USERNAME"
350
+				backup_directory_to_usb /root/tempbackupemail/$USERNAME mail/$USERNAME
351
+			fi
352
+
353
+			# Backup spamassassin
354
+			if [ -d /home/$USERNAME/.spamassassin ]; then
355
+				echo $"Backing up spamassassin settings for $USERNAME"
356
+				backup_directory_to_usb /home/$USERNAME/.spamassassin spamassassin/$USERNAME
357
+			fi
358
+
359
+			# Backup procmail
360
+			if [ -f /home/$USERNAME/.procmailrc ]; then
361
+				echo $"Backing up procmail settings for $USERNAME"
362
+				if [ ! -d /home/$USERNAME/tempbackup ]; then
363
+					mkdir -p /home/$USERNAME/tempbackup
364
+				fi
365
+				cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup
366
+				backup_directory_to_usb /home/$USERNAME/tempbackup procmail/$USERNAME
367
+			fi
368
+		fi
369
+	done
355 370
 }
356 371
 
357 372
 function backup_directories {
358
-    # directories to be backed up (source,dest)
359
-    backup_dirs=(
360
-        "none,                               none,       /etc/letsencrypt,                                letsencrypt"
361
-        "none,                               none,       /var/lib/dokuwiki,                               wiki"
362
-        "none,                               none,       /etc/dokuwiki,                                   wiki2"
363
-        "none,                               none,       /etc/ssl,                                        ssl"
364
-        "/etc/share/tt-rss,                  ttrss,      /root/tempttrssdata,                             ttrss"
365
-        "none,                               none,       /var/spool/mlmmj,                                mailinglist"
366
-        "none,                               none,       /var/lib/prosody,                                xmpp"
367
-        "none,                               none,       /etc/nginx/sites-available,                      web"
368
-        "none,                               none,       /home/$ADMIN_USERNAME/.ipfs,                     ipfs"
369
-        "none,                               none,       /var/cache/minidlna,                             dlna"
370
-        "/home/git/go/src/github.com/gogits, gogs,       /root/tempgogsdata,                              gogsdata"
371
-        "none,                               none,       /home/git/go/src/github.com/gogits/gogs/custom,  gogs"
372
-        "none,                               none,       /home/git/gogs-repositories,                     gogsrepos"
373
-        "none,                               none,       /home/git/.ssh,                                  gogsssh"
374
-        "none,                               none,       /var/lib/tox-bootstrapd,                         tox"
375
-        "/var/www/${MICROBLOG_DOMAIN_NAME},  gnusocial,  /root/tempgnusocialdata,                         gnusocialdata"
376
-        "none,                               none,       /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs,        gnusocial"
377
-        "/var/www/owncloud,                  owncloud,   /root/tempownclouddata,                          ownclouddata"
378
-        "none,                               none,       /var/www/owncloud/data,                          owncloudfiles"
379
-        "none,                               none,       /var/www/owncloud/config,                        owncloudconfig"
380
-        "/var/www/${HUBZILLA_DOMAIN_NAME},   hubzilla,   /root/temphubzilladata,                          hubzilladata"
381
-        "none,                               none,       /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs,         hubzilla"
382
-        "none,                               none,       /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs,         blog"
383
-        "none,                               none,       /var/lib/tor,                                    tor"
384
-        "none,                               none,       /var/www/${MEDIAGOBLIN_DOMAIN_NAME}/htdocs,      mediagoblin"
385
-    )
386
-
387
-    for dr in "${backup_dirs[@]}"
388
-    do
389
-        # if this directory exists then backup the given database
390
-        required_directory=$(echo $dr | awk -F ',' '{print $1}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
391
-        database_name=$(echo $dr | awk -F ',' '{print $2}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
392
-
393
-        if [[ "$database_name" == *"hubzilla"* ]]; then
394
-            suspend_site ${HUBZILLA_DOMAIN_NAME}
395
-        fi
396
-        if [[ "$database_name" == *"gnusocial"* ]]; then
397
-            suspend_site ${MICROBLOG_DOMAIN_NAME}
398
-        fi
399
-        if [[ "$database_name" == *"owncloud"* ]]; then
400
-            suspend_site ${OWNCLOUD_DOMAIN_NAME}
401
-        fi
402
-        if [[ "$database_name" == *"gogs"* ]]; then
403
-            suspend_site ${GIT_DOMAIN_NAME}
404
-        fi
405
-        if [[ "$database_name" == *"ttrss"* ]]; then
406
-            suspend_site ${RSS_READER_DOMAIN_NAME}
407
-        fi
408
-
409
-        if [[ $required_directory != "none" ]]; then
410
-            if [ -d $required_directory ]; then
411
-                if [[ $database_name != "none" ]]; then
412
-                    backup_database $database_name
413
-                fi
414
-            fi
415
-        fi
416
-
417
-        # if this directory exists then back it up to the given destination
418
-        source_directory=$(echo $dr | awk -F ',' '{print $3}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
419
-        if [ -d $source_directory ]; then
420
-            dest_directory=$(echo $dr | awk -F ',' '{print $4}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
421
-            echo $"Backing up $source_directory to $dest_directory"
422
-            backup_directory_to_usb $source_directory $dest_directory
423
-        fi
424
-
425
-        restart_site
426
-    done
373
+	# directories to be backed up (source,dest)
374
+	backup_dirs=(
375
+		"none,                               none,       /etc/letsencrypt,                                letsencrypt"
376
+		"none,                               none,       /var/lib/dokuwiki,                               wiki"
377
+		"none,                               none,       /etc/dokuwiki,                                   wiki2"
378
+		"none,                               none,       /etc/ssl,                                        ssl"
379
+		"/etc/share/tt-rss,                  ttrss,      /root/tempttrssdata,                             ttrss"
380
+		"none,                               none,       /var/spool/mlmmj,                                mailinglist"
381
+		"none,                               none,       /var/lib/prosody,                                xmpp"
382
+		"none,                               none,       /etc/nginx/sites-available,                      web"
383
+		"none,                               none,       /home/$ADMIN_USERNAME/.ipfs,                     ipfs"
384
+		"none,                               none,       /var/cache/minidlna,                             dlna"
385
+		"/home/git/go/src/github.com/gogits, gogs,       /root/tempgogsdata,                              gogsdata"
386
+		"none,                               none,       /home/git/go/src/github.com/gogits/gogs/custom,  gogs"
387
+		"none,                               none,       /home/git/gogs-repositories,                     gogsrepos"
388
+		"none,                               none,       /home/git/.ssh,                                  gogsssh"
389
+		"none,                               none,       /var/lib/tox-bootstrapd,                         tox"
390
+		"/var/www/${MICROBLOG_DOMAIN_NAME},  gnusocial,  /root/tempgnusocialdata,                         gnusocialdata"
391
+		"none,                               none,       /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs,        gnusocial"
392
+		"none,                               none,       /var/lib/syncthing/SyncShared,                   syncthingshared"
393
+		"none,                               none,       /root/.config/syncthing,                         syncthingconfig"
394
+		"/var/www/${HUBZILLA_DOMAIN_NAME},   hubzilla,   /root/temphubzilladata,                          hubzilladata"
395
+		"none,                               none,       /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs,         hubzilla"
396
+		"none,                               none,       /var/www/${FULLBLOG_DOMAIN_NAME}/htdocs,         blog"
397
+		"none,                               none,       /var/lib/tor,                                    tor"
398
+		"none,                               none,       /var/www/${MEDIAGOBLIN_DOMAIN_NAME}/htdocs,      mediagoblin"
399
+	)
400
+
401
+	for dr in "${backup_dirs[@]}"
402
+	do
403
+		# if this directory exists then backup the given database
404
+		required_directory=$(echo $dr | awk -F ',' '{print $1}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
405
+		database_name=$(echo $dr | awk -F ',' '{print $2}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
406
+
407
+		if [[ "$database_name" == *"hubzilla"* ]]; then
408
+			suspend_site ${HUBZILLA_DOMAIN_NAME}
409
+		fi
410
+		if [[ "$database_name" == *"gnusocial"* ]]; then
411
+			suspend_site ${MICROBLOG_DOMAIN_NAME}
412
+		fi
413
+		if [[ "$database_name" == *"gogs"* ]]; then
414
+			suspend_site ${GIT_DOMAIN_NAME}
415
+		fi
416
+		if [[ "$database_name" == *"ttrss"* ]]; then
417
+			suspend_site ${RSS_READER_DOMAIN_NAME}
418
+		fi
419
+
420
+		if [[ $required_directory != "none" ]]; then
421
+			if [ -d $required_directory ]; then
422
+				if [[ $database_name != "none" ]]; then
423
+					backup_database $database_name
424
+				fi
425
+			fi
426
+		fi
427
+
428
+		# if this directory exists then back it up to the given destination
429
+		source_directory=$(echo $dr | awk -F ',' '{print $3}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
430
+		if [ -d $source_directory ]; then
431
+			dest_directory=$(echo $dr | awk -F ',' '{print $4}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
432
+			echo $"Backing up $source_directory to $dest_directory"
433
+			backup_directory_to_usb $source_directory $dest_directory
434
+		fi
435
+
436
+		restart_site
437
+	done
427 438
 }
428 439
 
429 440
 function remove_backup_directory {
430
-    if [ $1 ]; then
431
-        if [[ $1 == "remove" ]]; then
432
-            if [ -d $USB_MOUNT/backup ]; then
433
-                rm -rf $USB_MOUNT/backup
434
-                echo $'Existing backup directory removed'
435
-                unmount_drive
436
-                exit 0
437
-            fi
438
-        fi
439
-    fi
441
+	if [ $1 ]; then
442
+		if [[ $1 == "remove" ]]; then
443
+			if [ -d $USB_MOUNT/backup ]; then
444
+				rm -rf $USB_MOUNT/backup
445
+				echo $'Existing backup directory removed'
446
+				unmount_drive
447
+				exit 0
448
+			fi
449
+		fi
450
+	fi
440 451
 }
441 452
 
442 453
 function prepare_directories {
443
-    # Some miscellaneous preparation for backing up directories
444
-    if [ -d /home/git/go/src/github.com/gogits ]; then
445
-        mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME
446
-    fi
447
-    if [ -d /var/lib/tox-bootstrapd ]; then
448
-        cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
449
-        if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
450
-            rm -rf /var/lib/tox-bootstrapd/Maildir
451
-        fi
452
-    fi
454
+	# Some miscellaneous preparation for backing up directories
455
+	if [ -d /home/git/go/src/github.com/gogits ]; then
456
+		mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME
457
+	fi
458
+	if [ -d /var/lib/tox-bootstrapd ]; then
459
+		cp /etc/tox-bootstrapd.conf /var/lib/tox-bootstrapd
460
+		if [ -d /var/lib/tox-bootstrapd/Maildir ]; then
461
+			rm -rf /var/lib/tox-bootstrapd/Maildir
462
+		fi
463
+	fi
453 464
 }
454 465
 
455 466
 function backup_configuration {
456
-    echo $"Backing up ${PROJECT_NAME} configuration files"
457
-    if [ ! -d /root/tempbackupconfig ]; then
458
-        mkdir -p /root/tempbackupconfig
459
-    fi
460
-    cp -f $CONFIG_FILE /root/tempbackupconfig
461
-    cp -f $COMPLETION_FILE /root/tempbackupconfig
462
-    if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
463
-        cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig
464
-    fi
465
-    # nginx password hashes
466
-    if [ -f /etc/nginx/.htpasswd ]; then
467
-        cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd
468
-    fi
469
-    backup_directory_to_usb /root/tempbackupconfig config
467
+	echo $"Backing up ${PROJECT_NAME} configuration files"
468
+	if [ ! -d /root/tempbackupconfig ]; then
469
+		mkdir -p /root/tempbackupconfig
470
+	fi
471
+	cp -f $CONFIG_FILE /root/tempbackupconfig
472
+	cp -f $COMPLETION_FILE /root/tempbackupconfig
473
+	if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
474
+		cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig
475
+	fi
476
+	# nginx password hashes
477
+	if [ -f /etc/nginx/.htpasswd ]; then
478
+		cp -f /etc/nginx/.htpasswd /root/tempbackupconfig/htpasswd
479
+	fi
480
+	backup_directory_to_usb /root/tempbackupconfig config
470 481
 }
471 482
 
472 483
 function backup_admin_readme {
473
-    if [ -f /home/$ADMIN_USERNAME/README ]; then
474
-        echo $"Backing up README"
475
-        if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then
476
-            mkdir -p /home/$ADMIN_USERNAME/tempbackup
477
-        fi
478
-        cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup
479
-        backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme
480
-    fi
484
+	if [ -f /home/$ADMIN_USERNAME/README ]; then
485
+		echo $"Backing up README"
486
+		if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then
487
+			mkdir -p /home/$ADMIN_USERNAME/tempbackup
488
+		fi
489
+		cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup
490
+		backup_directory_to_usb /home/$ADMIN_USERNAME/tempbackup readme
491
+	fi
481 492
 }
482 493
 
483 494
 function backup_voip {
484
-    if [ -f /etc/mumble-server.ini ]; then
485
-        echo $"Backing up VoIP settings"
486
-        if [ ! -d /root/tempvoipbackup ]; then
487
-            mkdir -p /root/tempvoipbackup
488
-        fi
489
-        cp -f /etc/mumble-server.ini /root/tempvoipbackup
490
-        cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup
491
-        cp -f /etc/sipwitch.conf /root/tempvoipbackup
492
-        backup_directory_to_usb /root/tempvoipbackup voip
493
-    fi
495
+	if [ -f /etc/mumble-server.ini ]; then
496
+		echo $"Backing up VoIP settings"
497
+		if [ ! -d /root/tempvoipbackup ]; then
498
+			mkdir -p /root/tempvoipbackup
499
+		fi
500
+		cp -f /etc/mumble-server.ini /root/tempvoipbackup
501
+		cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup
502
+		cp -f /etc/sipwitch.conf /root/tempvoipbackup
503
+		backup_directory_to_usb /root/tempvoipbackup voip
504
+	fi
494 505
 }
495 506
 
496 507
 function backup_mariadb {
497
-    if [ ${#DATABASE_PASSWORD} -gt 1 ]; then
498
-        if [ ! -d /root/tempmariadb ]; then
499
-            mkdir /root/tempmariadb
500
-        fi
501
-        mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql
502
-        if [ ! -s /root/tempmariadb/mysql.sql ]; then
503
-            echo $"Unable to backup mysql settings"
504
-            rm -rf /root/tempmariadb
505
-            umount $USB_MOUNT
506
-            rm -rf $USB_MOUNT
507
-            exit 8
508
-        fi
509
-        echo "$DATABASE_PASSWORD" > /root/tempmariadb/db
510
-        chmod 400 /root/tempmariadb/db
511
-        backup_directory_to_usb /root/tempmariadb mariadb
512
-    fi
508
+	if [ ${#DATABASE_PASSWORD} -gt 1 ]; then
509
+		if [ ! -d /root/tempmariadb ]; then
510
+			mkdir /root/tempmariadb
511
+		fi
512
+		mysqldump --lock-tables --password="$DATABASE_PASSWORD" mysql user > /root/tempmariadb/mysql.sql
513
+		if [ ! -s /root/tempmariadb/mysql.sql ]; then
514
+			echo $"Unable to backup mysql settings"
515
+			rm -rf /root/tempmariadb
516
+			umount $USB_MOUNT
517
+			rm -rf $USB_MOUNT
518
+			exit 8
519
+		fi
520
+		echo "$DATABASE_PASSWORD" > /root/tempmariadb/db
521
+		chmod 400 /root/tempmariadb/db
522
+		backup_directory_to_usb /root/tempmariadb mariadb
523
+	fi
513 524
 }
514 525
 
515 526
 function valid_backup_destination {
516
-    destination_dir="$1"
517
-    is_valid="yes"
518
-
519
-    if [[ "$destination_dir" == "hubzilla" || \
520
-                "$destination_dir" == "hubzilladata" || \
521
-                "$destination_dir" == "gogs" || \
522
-                "$destination_dir" == "gogsrepos" || \
523
-                "$destination_dir" == "gogsssh" || \
524
-                "$destination_dir" == "gnusocial" || \
525
-                "$destination_dir" == "gnusocialdata" || \
526
-                "$destination_dir" == "mariadb" || \
527
-                "$destination_dir" == "config" || \
528
-                "$destination_dir" == "letsencrypt" || \
529
-                "$destination_dir" == "wiki" || \
530
-                "$destination_dir" == "wiki2" || \
531
-                "$destination_dir" == "xmpp" || \
532
-                "$destination_dir" == "ipfs" || \
533
-                "$destination_dir" == "dlna" || \
534
-                "$destination_dir" == "tox" || \
535
-                "$destination_dir" == "ssl" || \
536
-                "$destination_dir" == "ttrss" || \
537
-                "$destination_dir" == "blog" || \
538
-                "$destination_dir" == "owncloudfiles" || \
539
-                "$destination_dir" == "owncloudconfig" || \
540
-                "$destination_dir" == "ownclouddata" || \
541
-                "$destination_dir" == "mediagoblin" || \
542
-                "$destination_dir" == "mailinglist" ]]; then
543
-        is_valid="no"
544
-    fi
545
-
546
-    echo $is_valid
527
+	destination_dir="$1"
528
+	is_valid="yes"
529
+
530
+	if [[ "$destination_dir" == "hubzilla" || \
531
+				"$destination_dir" == "hubzilladata" || \
532
+				"$destination_dir" == "gogs" || \
533
+				"$destination_dir" == "gogsrepos" || \
534
+				"$destination_dir" == "gogsssh" || \
535
+				"$destination_dir" == "gnusocial" || \
536
+				"$destination_dir" == "gnusocialdata" || \
537
+				"$destination_dir" == "mariadb" || \
538
+				"$destination_dir" == "config" || \
539
+				"$destination_dir" == "letsencrypt" || \
540
+				"$destination_dir" == "wiki" || \
541
+				"$destination_dir" == "wiki2" || \
542
+				"$destination_dir" == "xmpp" || \
543
+				"$destination_dir" == "ipfs" || \
544
+				"$destination_dir" == "dlna" || \
545
+				"$destination_dir" == "tox" || \
546
+				"$destination_dir" == "ssl" || \
547
+				"$destination_dir" == "ttrss" || \
548
+				"$destination_dir" == "blog" || \
549
+				"$destination_dir" == "syncthingconfig" || \
550
+				"$destination_dir" == "syncthingshared" || \
551
+				"$destination_dir" == "syncthing" || \
552
+				"$destination_dir" == "mediagoblin" || \
553
+				"$destination_dir" == "mailinglist" ]]; then
554
+		is_valid="no"
555
+	fi
556
+
557
+	echo $is_valid
547 558
 }
548 559
 
549 560
 function backup_extra_directories {
550
-    if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
551
-        return
552
-    fi
553
-
554
-    echo $"Backing up some additional directories"
555
-    while read backup_line
556
-    do
557
-        backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
558
-        if [ -d "$backup_dir" ]; then
559
-            destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
560
-            if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
561
-                backup_directory_to_usb "$backup_dir" "$destination_dir"
562
-            else
563
-                echo $"WARNING: The backup directory $destination_dir is already used."
564
-                echo $"Choose a different destination name for backing up $backup_dir"
565
-            fi
566
-        else
567
-            echo $"WARNING: Directory $backup_dir does not exist"
568
-        fi
569
-    done <$BACKUP_EXTRA_DIRECTORIES
561
+	if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then
562
+		return
563
+	fi
564
+
565
+	echo $"Backing up some additional directories"
566
+	while read backup_line
567
+	do
568
+		backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
569
+		if [ -d "$backup_dir" ]; then
570
+			destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
571
+			if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then
572
+				backup_directory_to_usb "$backup_dir" "$destination_dir"
573
+			else
574
+				echo $"WARNING: The backup directory $destination_dir is already used."
575
+				echo $"Choose a different destination name for backing up $backup_dir"
576
+			fi
577
+		else
578
+			echo $"WARNING: Directory $backup_dir does not exist"
579
+		fi
580
+	done <$BACKUP_EXTRA_DIRECTORIES
570 581
 }
571 582
 
572 583
 # has the remove option been set ?
573 584
 remove_option=$2
574 585
 if [[ $1 == "remove" ]]; then
575
-    remove_option=$1
586
+	remove_option=$1
576 587
 fi
577 588
 
578 589
 mount_drive $1 $2

+ 31
- 16
src/freedombone-backup-remote View File

@@ -202,6 +202,25 @@ function backup_users {
202 202
                 backup_directory_to_friend /home/$USERNAME/.ssh ssh/$USERNAME
203 203
             fi
204 204
 
205
+            # syncthing files
206
+            if [ -d /home/$USERNAME/Sync ]; then
207
+                echo $"Backing up syncthing files for $USERNAME"
208
+                backup_directory_to_friend /home/$USERNAME/Sync syncthing/$USERNAME
209
+				# ensure that device IDs will be backed up as part of user config settings
210
+				if [ ! -d /home/$USERNAME/.config/syncthing ]; then
211
+					mkdir -p /home/$USERNAME/.config/syncthing
212
+					chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
213
+				fi					
214
+				if [ -f /home/$USERNAME/.syncthing-server-id ]; then
215
+					cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
216
+					chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
217
+				fi				
218
+				if [ -f /home/$USERNAME/.syncthingids ]; then
219
+					cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
220
+					chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
221
+				fi				
222
+            fi
223
+
205 224
             # config files
206 225
             if [ -d /home/$USERNAME/.config ]; then
207 226
                 echo $"Backing up config files for $USERNAME"
@@ -326,18 +345,14 @@ function backup_hubzilla {
326 345
     fi
327 346
 }
328 347
 
329
-function backup_owncloud {
330
-    if [ -d /etc/owncloud ]; then
331
-        OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
332
-        suspend_site ${OWNCLOUD_DOMAIN_NAME}
333
-        backup_database_to_friend owncloud
334
-        backup_directory_to_friend /root/tempownclouddata ownclouddata
335
-        echo $"Backing up Owncloud data"
336
-        if [ -d /var/www/owncloud/data ]; then
337
-            backup_directory_to_friend /var/www/owncloud/data owncloudfiles
338
-        fi
339
-        backup_directory_to_friend /var/www/owncloud/config owncloudconfig
340
-        restart_site
348
+function backup_syncthing {
349
+    if [ -d /root/.config/syncthing ]; then
350
+        echo $"Backing up syncthing configuration"
351
+        backup_directory_to_friend /root/.config/syncthing syncthingconfig
352
+    fi
353
+    if [ -d /var/lib/syncthing/SyncShared ]; then
354
+		echo $"Backing up syncthing shared files"
355
+		backup_directory_to_friend /var/lib/syncthing/SyncShared syncthingshared
341 356
     fi
342 357
 }
343 358
 
@@ -566,9 +581,9 @@ function valid_backup_destination {
566 581
                 "$destination_dir" == "tox" || \
567 582
                 "$destination_dir" == "ssl" || \
568 583
                 "$destination_dir" == "blog" || \
569
-                "$destination_dir" == "owncloudfiles" || \
570
-                "$destination_dir" == "owncloudconfig" || \
571
-                "$destination_dir" == "ownclouddata" || \
584
+                "$destination_dir" == "syncthing" || \
585
+                "$destination_dir" == "syncthingconfig" || \
586
+                "$destination_dir" == "syncthingshared" || \
572 587
                 "$destination_dir" == "mailinglist" ]]; then
573 588
         is_valid="no"
574 589
     fi
@@ -612,7 +627,7 @@ if [[ $TEST_MODE == "no" ]]; then
612 627
     backup_gnusocial
613 628
     backup_rss_reader
614 629
     backup_hubzilla
615
-    backup_owncloud
630
+    backup_syncthing
616 631
     backup_mediagoblin
617 632
     backup_gogs
618 633
     backup_wiki

+ 728
- 698
src/freedombone-restore-local
File diff suppressed because it is too large
View File


+ 63
- 31
src/freedombone-restore-remote View File

@@ -693,48 +693,80 @@ function restore_hubzilla {
693 693
     fi
694 694
 }
695 695
 
696
-function restore_owncloud {
696
+function restore_syncthing {
697 697
     if [[ $RESTORE_APP != 'all' ]]; then
698
-        if [[ $RESTORE_APP != 'owncloud' ]]; then
698
+        if [[ $RESTORE_APP != 'syncthing' ]]; then
699 699
             return
700 700
         fi
701 701
     fi
702
-    OWNCLOUD_PATH=/var/www/owncloud
703
-    if grep -q "Owncloud domain" $COMPLETION_FILE; then
704
-        OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
705
-        restore_database_from_friend owncloud $OWNCLOUD_DOMAIN_NAME
706
-
707
-        if [ -d $SERVER_DIRECTORY/backup/owncloudfiles ]; then
708
-            echo $"Restoring Owncloud installation"
709
-            restore_directory_from_friend /root/tempowncloudfiles owncloudfiles
710
-            cp -r /root/tempowncloudfiles/* /
711
-            if [ ! "$?" = "0" ]; then
712
-                exit 1458
713
-            fi
714
-            rm -rf /root/tempowncloudfiles
715
-        fi
716 702
 
717
-        if [ -d $SERVER_DIRECTORY/backup/owncloudconfig ]; then
718
-            echo $"Restoring Owncloud installation"
719
-            restore_directory_from_friend /root/tempowncloudconfig owncloudconfig
720
-            cp -r /root/tempowncloudconfig/* /
721
-            if [ ! "$?" = "0" ]; then
722
-                exit 2571
723
-            fi
724
-            rm -rf /root/tempowncloudconfig
703
+    if [ -f /etc/systemd/system/syncthing.service ]; then
704
+        systemctl stop syncthing
705
+        systemctl stop cron
706
+    fi
707
+    
708
+    if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
709
+        echo $"Restoring syncthing configuration"
710
+        restore_directory_from_friend /root/tempsyncthingconfig syncthingconfig
711
+        cp -r /root/tempsyncthingconfig/* /
712
+        if [ ! "$?" = "0" ]; then
713
+            unmount_drive
714
+            systemctl start syncthing
715
+            systemctl start cron
716
+            exit 6833
725 717
         fi
718
+        rm -rf /root/tempsyncthingconfig
719
+    fi
726 720
 
727
-        chown -R www-data:www-data $OWNCLOUD_PATH
728
-        chown root:root $OWNCLOUD_PATH/config/config.php
721
+    if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
722
+        echo $"Restoring syncthing shared files"
723
+        restore_directory_from_friend /root/tempsyncthingshared syncthingshared
724
+        cp -r /root/tempsyncthingshared/* /
725
+        if [ ! "$?" = "0" ]; then
726
+            unmount_drive
727
+            systemctl start syncthing
728
+            systemctl start cron
729
+            exit 37904
730
+        fi
731
+        rm -rf /root/tempsyncthingshared
732
+    fi
729 733
 
730
-        # re-index files
731
-        for d in /home/*/ ; do
732
-            USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
734
+    if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
735
+        for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
736
+            USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
733 737
             if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
734
-                $OWNCLOUD_PATH/occ files:scan $USERNAME
738
+                if [ ! -d /home/$USERNAME ]; then
739
+                    ${PROJECT_NAME}-adduser $USERNAME
740
+                fi
741
+                echo $"Restoring syncthing files for $USERNAME"
742
+                restore_directory_from_friend /root/tempsyncthing syncthing/$USERNAME
743
+                cp -r /root/tempsyncthing/home/$USERNAME/Sync /home/$USERNAME/
744
+                if [ ! "$?" = "0" ]; then
745
+                    rm -rf /root/tempsyncthing
746
+                    unmount_drive
747
+                    systemctl start syncthing
748
+                    systemctl start cron
749
+                    exit 68438
750
+                fi
751
+                rm -rf /root/tempsyncthing
752
+
753
+                # restore device IDs from config settings
754
+                if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
755
+                    cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
756
+                    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
757
+                fi
758
+                if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
759
+                    cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
760
+                    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
761
+                fi              
735 762
             fi
736 763
         done
737 764
     fi
765
+
766
+    if [ -f /etc/systemd/system/syncthing.service ]; then
767
+        systemctl start syncthing
768
+        systemctl start cron
769
+    fi
738 770
 }
739 771
 
740 772
 function restore_mediagoblin {
@@ -1014,7 +1046,7 @@ restore_xmpp
1014 1046
 restore_gnu_social
1015 1047
 restore_hubzilla
1016 1048
 restore_rss_reader
1017
-restore_owncloud
1049
+restore_syncthing
1018 1050
 restore_mediagoblin
1019 1051
 restore_gogs
1020 1052
 restore_wiki