diff options
author | Von Random <von@mechanus.net> | 2015-01-13 12:53:59 +0300 |
---|---|---|
committer | Von Random <von@mechanus.net> | 2015-01-13 12:53:59 +0300 |
commit | b5d0158936bdd7d2664581b7404fe380c3f36791 (patch) | |
tree | e2cfc54d34c1ba95da980146438f37b0c6f423ea | |
parent | 175c7979f9d5d8ac91e61ce4f82f747f9b8d2531 (diff) |
added encryption support and fixed a couple of comments
-rw-r--r-- | backup.cfg | 4 | ||||
-rwxr-xr-x | backup.zsh | 18 |
2 files changed, 19 insertions, 3 deletions
@@ -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' @@ -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 } |