|
@@ -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
|
|