Skip to content

Commit 7320f93

Browse files
authored
Merge pull request #47 from Clicface/master
Adding GPG encryption
2 parents 26d95ce + 3879c00 commit 7320f93

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

automysqlbackup

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ load_default_config() {
113113
CONFIG_mail_address='root'
114114
CONFIG_encrypt='no'
115115
CONFIG_encrypt_password='password0123'
116+
CONFIG_gpg_encrypt='no'
117+
CONFIG_gpg_encrypt_recipient='SHORT_ID'
116118
}
117119

118120
mysql_commands() {
@@ -365,6 +367,27 @@ files_postprocessing () {
365367
}
366368
# <- CONFIG_encrypt
367369

370+
# -> CONFIG_gpg_encrypt
371+
[[ "${CONFIG_gpg_encrypt}" = "yes" && "${CONFIG_gpg_encrypt_recipient}" ]] && {
372+
if (( $CONFIG_dryrun )); then
373+
printf 'dry-running: gpg --encrypt --recipient ${CONFIG_gpg_encrypt_recipient} --output ${1}.gpg --batch ${1}'
374+
else
375+
gpg --encrypt --recipient ${CONFIG_gpg_encrypt_recipient} --output ${1}.gpg --batch ${1}
376+
if (( $? == 0 )); then
377+
if rm ${1} 2>&1; then
378+
echo "Successfully encrypted archive as ${1}.gpg"
379+
let "flags |= $flags_files_postprocessing_success_encrypt"
380+
else
381+
echo "Successfully encrypted archive as ${1}.gpg, but could not remove cleartext file ${1}."
382+
let "E |= $E_enc_cleartext_delfailed"
383+
fi
384+
else
385+
let "E |= $E_enc_failed"
386+
fi
387+
fi
388+
}
389+
# <- CONFIG_gpg_encrypt
390+
368391
# -> CONFIG_mysql_dump_latest
369392
[[ "${CONFIG_mysql_dump_latest}" = "yes" ]] && {
370393
if (( $flags & $flags_files_postprocessing_success_encrypt )); then
@@ -781,7 +804,7 @@ process_dbs() {
781804
db="$1"
782805
fi
783806

784-
if [[ "x$CONFIG_mysql_dump_differential" = "xyes" ]] && [[ "x${CONFIG_encrypt}" != "xyes" ]] && (( $activate_differential_backup )); then
807+
if [[ "x$CONFIG_mysql_dump_differential" = "xyes" ]] && [[ "x${CONFIG_encrypt}" != "xyes" ]] && [[ "x${CONFIG_gpg_encrypt}" != "xyes" ]] && (( $activate_differential_backup )); then
785808

786809

787810
unset manifest_entry manifest_entry_to_check
@@ -835,7 +858,7 @@ process_dbs() {
835858

836859
fi
837860

838-
if [[ "x$CONFIG_mysql_dump_differential" = "xyes" ]] && [[ "x${CONFIG_encrypt}" != "xyes" ]] && (( $activate_differential_backup )) && ((! ($filename_flags & $filename_flag_encrypted) )); then
861+
if [[ "x$CONFIG_mysql_dump_differential" = "xyes" ]] && [[ "x${CONFIG_encrypt}" != "xyes" ]] && [[ "x${CONFIG_gpg_encrypt}" != "xyes" ]] && (( $activate_differential_backup )) && ((! ($filename_flags & $filename_flag_encrypted) )); then
839862

840863
# the master file is encrypted ... well this just shouldn't happen ^^ not going to decrypt or stuff like that ...at least not today :)
841864

automysqlbackup.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ CONFIG_db_exclude_pattern=()
264264
# Choose a password to encrypt the backups.
265265
#CONFIG_encrypt_password='password0123'
266266

267+
# Do you wish to encrypt your backups using GPG?
268+
#CONFIG_gpg_encrypt='no'
269+
270+
# ID of the Public PGP Key to use. The key must already be in your keyring.
271+
#CONFIG_gpg_encrypt_recipient='SHORT_ID'
272+
267273
# Other
268274

269275
# Backup local files, i.e. maybe you would like to backup your my.cnf (mysql server configuration), etc.

0 commit comments

Comments
 (0)