From b5d0158936bdd7d2664581b7404fe380c3f36791 Mon Sep 17 00:00:00 2001 From: Von Random Date: Tue, 13 Jan 2015 12:53:59 +0300 Subject: added encryption support and fixed a couple of comments --- backup.cfg | 4 ++++ backup.zsh | 18 +++++++++++++++--- 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 } -- cgit v1.2.3