diff options
author | David Runge <dave@sleepmap.de> | 2015-10-26 22:37:11 +0100 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2015-10-26 22:37:11 +0100 |
commit | 000f49c33c736f56bf5b9a0d6aedca74e0ae72dc (patch) | |
tree | b898d6ce650450627a8aabf58b657c15d7fe9fef /bin/crypted-backups | |
parent | e137a9974e55221c619f2cb4804120ee1efbb15d (diff) | |
download | crypted-backups-000f49c33c736f56bf5b9a0d6aedca74e0ae72dc.tar.gz crypted-backups-000f49c33c736f56bf5b9a0d6aedca74e0ae72dc.tar.bz2 crypted-backups-000f49c33c736f56bf5b9a0d6aedca74e0ae72dc.tar.xz crypted-backups-000f49c33c736f56bf5b9a0d6aedca74e0ae72dc.zip |
bin/crypted-backups: Distinguishing between checking for folder's existence and its additional creation upon non-existence. Adding message on empty subfolders when doing recursive backup. Adding check for configuration file.
Diffstat (limited to 'bin/crypted-backups')
-rwxr-xr-x | bin/crypted-backups | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/bin/crypted-backups b/bin/crypted-backups index e2dc887..5de0b7c 100755 --- a/bin/crypted-backups +++ b/bin/crypted-backups @@ -2,7 +2,12 @@ set -euo pipefail IFS=$'\n\t' -. /etc/crypted-backups +if [ -r /etc/crypted-backups ]; then + . /etc/crypted-backups +else + echo "Configuration file (/etc/crypted-backups) not readable! Aborting!" + exit 1 +fi user_mode="" source_mode="" verbose='' @@ -75,6 +80,16 @@ function check_database_settings () { function check_directory_exists () { local destination=$1 if [ ! -d $destination ]; then + echo "Directory \"$destination\" does not exist!" + return 1 + else + return 0 + fi +} + +function check_directory_exists_and_autocreate () { + local destination=$1 + if [ ! -d $destination ]; then echo "Directory \"$destination\" does not exist yet. Creating..." mkdir -p $destination else @@ -111,14 +126,15 @@ function check_directory_owner_user() { function check_user_directory () { local directory=$1 - check_directory_exists $directory + echo "Checking directory \"$directory\"." + check_directory_exists_and_autocreate $directory check_directory_writable_user $directory return 0 } function check_root_directory () { local directory=$1 - check_directory_exists $directory + check_directory_exists_and_autocreate $directory check_directory_permission_root $directory return 0 } @@ -167,12 +183,21 @@ function compress_to_tmp_file () { function encrypt_tmp_file () { local tmp_file=$1 local destination_file=$2 + local encrypt_return=-1 echo "Encrypting $tmp_file to $destination_file." - #TODO: Failover for still deleting $tmp_file, if encryption fails + set +eu gpg -e \ -r "$gpg_public_key" \ -o "$destination_file" \ "$tmp_file" + encrypt_return=$? + set -eu + if [ $encrypt_return -gt 0 ];then + echo "GnuPG encryption returns with: $encrypt_return" + echo "Removing $tmp_file." + rm -f "$tmp_file" + return 1 + fi echo "Removing $tmp_file." rm -f "$tmp_file" return 0 @@ -190,7 +215,6 @@ function backup_single_directory () { notification_source_to_destination "$source_parent_directory$source_directory_basename" $destination_file echo "Going to $source_directory_basename's parent directory: $source_parent_directory." cd $source_parent_directory - #TODO: check if directory, not for existence? check_directory_exists $source_directory "check_"$user_mode"_directory" $tmp_directory "check_"$user_mode"_directory" $destination_directory @@ -202,14 +226,17 @@ function backup_multiple_directories () { local source_directory=$(sanitize_pathname $1) local destination_directory=$(sanitize_pathname $2) local layered=0 + local sub_count=0 if [ ${#@} -gt 2 ]; then layered=$3 - echo "Multi-layered" + echo "Recursive backup (depth=1) of \"$source_directory\"." fi + check_directory_exists $source_directory "check_"$user_mode"_directory" $destination_directory for sub_directory in $source_directory* do if [ -d $sub_directory ];then + sub_count=$((sub_count+1)) "check_"$user_mode"_directory" $sub_directory if [ $layered -eq 1 ];then backup_multiple_directories $sub_directory $destination_directory$(get_basename_directory $sub_directory) @@ -218,7 +245,9 @@ function backup_multiple_directories () { fi fi done - + if [ $sub_count -eq 0 ]; then + echo "There are actually no folders to backup in \"$source_directory\". Please check the configuration file!" + fi } function dump_database () { @@ -292,11 +321,9 @@ function print_help () { exit 0 } -#TODO: Add function to delete compressed data in working directory (also after fail) #TODO: Add function to cleanup backups #TODO: Add function to mirror backups #TODO: Add function to automatically add key to keyring, if not found -#TODO: Create logic to distinguish between different backups #TODO: Add verbose flag |