소스 검색

Temp directory for duplicity

Bob Mottram 7 년 전
부모
커밋
a8e7aeb497
1개의 변경된 파일31개의 추가작업 그리고 7개의 파일을 삭제
  1. 31
    7
      src/freedombone-utils-backup

+ 31
- 7
src/freedombone-utils-backup 파일 보기

13
 # License
13
 # License
14
 # =======
14
 # =======
15
 #
15
 #
16
-# Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
16
+# Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
17
 #
17
 #
18
 # This program is free software: you can redistribute it and/or modify
18
 # This program is free software: you can redistribute it and/or modify
19
 # it under the terms of the GNU Affero General Public License as published by
19
 # it under the terms of the GNU Affero General Public License as published by
34
 # Dummy password used for the backup key
34
 # Dummy password used for the backup key
35
 BACKUP_DUMMY_PASSWORD='backup'
35
 BACKUP_DUMMY_PASSWORD='backup'
36
 
36
 
37
+BACKUP_TEMP_DIRECTORY=/root/.backuptemp
38
+
39
+function create_backups_temp_directory {
40
+    if [ ! -d $BACKUP_TEMP_DIRECTORY ]; then
41
+        mkdir $BACKUP_TEMP_DIRECTORY
42
+    fi
43
+}
44
+
45
+function remove_backups_temp_directory {
46
+    if [ -d $BACKUP_TEMP_DIRECTORY ]; then
47
+        rm -rf $BACKUP_TEMP_DIRECTORY
48
+    fi
49
+}
50
+
37
 function suspend_site {
51
 function suspend_site {
38
     # suspends a given website
52
     # suspends a given website
39
     SUSPENDED_SITE="$1"
53
     SUSPENDED_SITE="$1"
248
 }
262
 }
249
 
263
 
250
 function backup_directory_to_usb_duplicity {
264
 function backup_directory_to_usb_duplicity {
251
-    echo "$BACKUP_DUMMY_PASSWORD" | duplicity full --encrypt-key $MY_BACKUP_KEY_ID --full-if-older-than 4W --exclude-other-filesystems ${1} file://$USB_MOUNT/backup/${2}
265
+    create_backups_temp_directory
266
+    echo "$BACKUP_DUMMY_PASSWORD" | duplicity full --tempdir $BACKUP_TEMP_DIRECTORY --encrypt-key $MY_BACKUP_KEY_ID --full-if-older-than 4W --exclude-other-filesystems ${1} file://$USB_MOUNT/backup/${2}
252
     if [[ $ENABLE_BACKUP_VERIFICATION == "yes" ]]; then
267
     if [[ $ENABLE_BACKUP_VERIFICATION == "yes" ]]; then
253
-        echo "$BACKUP_DUMMY_PASSWORD" | duplicity verify --encrypt-key $MY_BACKUP_KEY_ID --full-if-older-than 4W --exclude-other-filesystems ${1} file://$USB_MOUNT/backup/${2}
268
+        echo "$BACKUP_DUMMY_PASSWORD" | duplicity verify --tempdir $BACKUP_TEMP_DIRECTORY --encrypt-key $MY_BACKUP_KEY_ID --full-if-older-than 4W --exclude-other-filesystems ${1} file://$USB_MOUNT/backup/${2}
254
         if [ ! "$?" = "0" ]; then
269
         if [ ! "$?" = "0" ]; then
255
             umount $USB_MOUNT
270
             umount $USB_MOUNT
256
             rm -rf $USB_MOUNT
271
             rm -rf $USB_MOUNT
260
             fi
275
             fi
261
             function_check restart_site
276
             function_check restart_site
262
             restart_site
277
             restart_site
278
+            remove_backups_temp_directory
263
             exit 683252
279
             exit 683252
264
         fi
280
         fi
265
     fi
281
     fi
282
+    remove_backups_temp_directory
266
 }
283
 }
267
 
284
 
268
 function backup_directory_to_usb_obnam {
285
 function backup_directory_to_usb_obnam {
330
 }
347
 }
331
 
348
 
332
 function restore_directory_from_usb_duplicity {
349
 function restore_directory_from_usb_duplicity {
333
-    echo "$BACKUP_DUMMY_PASSWORD" | duplicity restore --force file://$USB_MOUNT/backup/${2} ${1}
350
+    create_backups_temp_directory
351
+    echo "$BACKUP_DUMMY_PASSWORD" | duplicity restore --tempdir $BACKUP_TEMP_DIRECTORY --force file://$USB_MOUNT/backup/${2} ${1}
352
+    remove_backups_temp_directory
334
 }
353
 }
335
 
354
 
336
 function restore_directory_from_usb {
355
 function restore_directory_from_usb {
357
 }
376
 }
358
 
377
 
359
 function restore_directory_from_friend_duplicity {
378
 function restore_directory_from_friend_duplicity {
360
-    echo "$BACKUP_DUMMY_PASSWORD" | duplicity restore --force file://$SERVER_DIRECTORY/backup/${2} ${1}
379
+    create_backups_temp_directory
380
+    echo "$BACKUP_DUMMY_PASSWORD" | duplicity restore --tempdir $BACKUP_TEMP_DIRECTORY --force file://$SERVER_DIRECTORY/backup/${2} ${1}
381
+    remove_backups_temp_directory
361
 }
382
 }
362
 
383
 
363
 function restore_directory_from_friend {
384
 function restore_directory_from_friend {
401
 }
422
 }
402
 
423
 
403
 function backup_directory_to_friend_duplicity {
424
 function backup_directory_to_friend_duplicity {
404
-    echo "$BACKUP_DUMMY_PASSWORD" | duplicity full --ssh-askpass --encrypt-key ${ADMIN_BACKUP_KEY_ID} --full-if-older-than 4W --exclude-other-filesystems ${1} $SERVER_DIRECTORY/backup/${2}
425
+    create_backups_temp_directory
426
+    echo "$BACKUP_DUMMY_PASSWORD" | duplicity full --tempdir $BACKUP_TEMP_DIRECTORY --ssh-askpass --encrypt-key ${ADMIN_BACKUP_KEY_ID} --full-if-older-than 4W --exclude-other-filesystems ${1} $SERVER_DIRECTORY/backup/${2}
405
     if [[ $ENABLE_BACKUP_VERIFICATION == "yes" ]]; then
427
     if [[ $ENABLE_BACKUP_VERIFICATION == "yes" ]]; then
406
-        echo "$BACKUP_DUMMY_PASSWORD" | duplicity verify --ssh-askpass --encrypt-key ${ADMIN_BACKUP_KEY_ID} --full-if-older-than 4W --exclude-other-filesystems ${1} $SERVER_DIRECTORY/backup/${2}
428
+        echo "$BACKUP_DUMMY_PASSWORD" | duplicity verify --tempdir $BACKUP_TEMP_DIRECTORY --ssh-askpass --encrypt-key ${ADMIN_BACKUP_KEY_ID} --full-if-older-than 4W --exclude-other-filesystems ${1} $SERVER_DIRECTORY/backup/${2}
407
         if [ ! "$?" = "0" ]; then
429
         if [ ! "$?" = "0" ]; then
408
             if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
430
             if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
409
                 shred -zu ${1}/*
431
                 shred -zu ${1}/*
411
             fi
433
             fi
412
             function_check restart_site
434
             function_check restart_site
413
             restart_site
435
             restart_site
436
+            remove_backups_temp_directory
414
             exit 683252
437
             exit 683252
415
         fi
438
         fi
416
     fi
439
     fi
440
+    remove_backups_temp_directory
417
 }
441
 }
418
 
442
 
419
 function backup_directory_to_friend_obnam {
443
 function backup_directory_to_friend_obnam {