summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVon Random <von@mechanus.net>2015-01-13 12:53:59 +0300
committerVon Random <von@mechanus.net>2015-01-13 12:53:59 +0300
commitb5d0158936bdd7d2664581b7404fe380c3f36791 (patch)
treee2cfc54d34c1ba95da980146438f37b0c6f423ea
parent175c7979f9d5d8ac91e61ce4f82f747f9b8d2531 (diff)
added encryption support and fixed a couple of comments
-rw-r--r--backup.cfg4
-rwxr-xr-xbackup.zsh18
2 files changed, 19 insertions, 3 deletions
diff --git a/backup.cfg b/backup.cfg
index 982df09..c852c98 100644
--- a/backup.cfg
+++ b/backup.cfg
@@ -31,6 +31,10 @@ source_dirs=( '/home/user/source1:/var/backup/snapshot.list'
## externally.
#backup_filename='somebackup'
+## GPG key to encrypt backups, uses name of the private
+## key in your keyring
+#gnupg_key='keyname'
+
#### remote options ####
## Remote host.
remote_host='hostname.tld'
diff --git a/backup.zsh b/backup.zsh
index ea3847f..34454af 100755
--- a/backup.zsh
+++ b/backup.zsh
@@ -1,5 +1,7 @@
#!/usr/bin/env zsh
self_name=$0
+
+# some hardcoded defaults
default_cfg='/etc/backup.zsh.cfg'
default_postfix=$(date +%F-%H%M)
default_ftp_port='21'
@@ -104,7 +106,7 @@ function generate_fullpath
backup_type='full'
fi
if [[ -z $backup_filename ]]; then
- outfile="$backup_dir/${local_host}-${src_basename}_${postfix}_${backup_type}.t${compress_format:-'ar'}"
+ outfile="$backup_dir/${local_host}-${src_basename}_${postfix}_${backup_type}${gnupg_key:+'.gpg.'}.t${compress_format:-'ar'}"
else
outfile=$backup_filename
fi
@@ -136,7 +138,13 @@ function store
esac
}
-# self explanatory, using case statement, so no one dash multiple opts supported
+# encrypt asymmetrically via gpg
+function encrypt
+{
+ gpg -r $gnupg_key -e -
+}
+
+# self explanatory, using case statement, so one dash multiple opts is not supported
function parse_opts
{
while [[ -n $1 ]]; do
@@ -171,7 +179,11 @@ function main
generate_fullpath
err "Creating a backup of $source_dir via $protocol to store it in $outfile."
# pipe magic into magic
- compress | store
+ if [[ -n $gnupg_key ]]; then
+ compress | encrypt | store
+ else
+ compress | store
+ fi
done
return 0
}