|  | @@ -13,7 +13,7 @@
 | 
	
		
			
			| 13 | 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 | 18 |  # This program is free software: you can redistribute it and/or modify
 | 
	
		
			
			| 19 | 19 |  # it under the terms of the GNU Affero General Public License as published by
 | 
	
	
		
			
			|  | @@ -34,6 +34,20 @@ SUSPENDED_SITE=
 | 
	
		
			
			| 34 | 34 |  # Dummy password used for the backup key
 | 
	
		
			
			| 35 | 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 | 51 |  function suspend_site {
 | 
	
		
			
			| 38 | 52 |      # suspends a given website
 | 
	
		
			
			| 39 | 53 |      SUSPENDED_SITE="$1"
 | 
	
	
		
			
			|  | @@ -248,9 +262,10 @@ function set_obnam_client_name {
 | 
	
		
			
			| 248 | 262 |  }
 | 
	
		
			
			| 249 | 263 |  
 | 
	
		
			
			| 250 | 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 | 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 | 269 |          if [ ! "$?" = "0" ]; then
 | 
	
		
			
			| 255 | 270 |              umount $USB_MOUNT
 | 
	
		
			
			| 256 | 271 |              rm -rf $USB_MOUNT
 | 
	
	
		
			
			|  | @@ -260,9 +275,11 @@ function backup_directory_to_usb_duplicity {
 | 
	
		
			
			| 260 | 275 |              fi
 | 
	
		
			
			| 261 | 276 |              function_check restart_site
 | 
	
		
			
			| 262 | 277 |              restart_site
 | 
	
		
			
			|  | 278 | +            remove_backups_temp_directory
 | 
	
		
			
			| 263 | 279 |              exit 683252
 | 
	
		
			
			| 264 | 280 |          fi
 | 
	
		
			
			| 265 | 281 |      fi
 | 
	
		
			
			|  | 282 | +    remove_backups_temp_directory
 | 
	
		
			
			| 266 | 283 |  }
 | 
	
		
			
			| 267 | 284 |  
 | 
	
		
			
			| 268 | 285 |  function backup_directory_to_usb_obnam {
 | 
	
	
		
			
			|  | @@ -330,7 +347,9 @@ function restore_directory_from_usb_obnam {
 | 
	
		
			
			| 330 | 347 |  }
 | 
	
		
			
			| 331 | 348 |  
 | 
	
		
			
			| 332 | 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 | 355 |  function restore_directory_from_usb {
 | 
	
	
		
			
			|  | @@ -357,7 +376,9 @@ function restore_directory_from_friend_obnam {
 | 
	
		
			
			| 357 | 376 |  }
 | 
	
		
			
			| 358 | 377 |  
 | 
	
		
			
			| 359 | 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 | 384 |  function restore_directory_from_friend {
 | 
	
	
		
			
			|  | @@ -401,9 +422,10 @@ function set_user_permissions {
 | 
	
		
			
			| 401 | 422 |  }
 | 
	
		
			
			| 402 | 423 |  
 | 
	
		
			
			| 403 | 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 | 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 | 429 |          if [ ! "$?" = "0" ]; then
 | 
	
		
			
			| 408 | 430 |              if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
 | 
	
		
			
			| 409 | 431 |                  shred -zu ${1}/*
 | 
	
	
		
			
			|  | @@ -411,9 +433,11 @@ function backup_directory_to_friend_duplicity {
 | 
	
		
			
			| 411 | 433 |              fi
 | 
	
		
			
			| 412 | 434 |              function_check restart_site
 | 
	
		
			
			| 413 | 435 |              restart_site
 | 
	
		
			
			|  | 436 | +            remove_backups_temp_directory
 | 
	
		
			
			| 414 | 437 |              exit 683252
 | 
	
		
			
			| 415 | 438 |          fi
 | 
	
		
			
			| 416 | 439 |      fi
 | 
	
		
			
			|  | 440 | +    remove_backups_temp_directory
 | 
	
		
			
			| 417 | 441 |  }
 | 
	
		
			
			| 418 | 442 |  
 | 
	
		
			
			| 419 | 443 |  function backup_directory_to_friend_obnam {
 |