I want to password protect a gzip file generated using mysqldump.
mysqldump -u [uname] -p db_name | gzip > db_backup.sql.gz
any ideas how to? would be better if i can achieve this using a one-line command.
P.S: using Nodejs to execute child process.
I want to password protect a gzip file generated using mysqldump.
mysqldump -u [uname] -p db_name | gzip > db_backup.sql.gz
any ideas how to? would be better if i can achieve this using a one-line command.
P.S: using Nodejs to execute child process.
Not tested but the below should work:
Create a key
openssl req -x509 -nodes -newkey rsa:2048 -keyout mysqldump-secure.priv.pem -out mysqldump-secure.pub.pem
Use the public key to encrypt
mysqldump -u [uname] -p db_name | gzip -c | openssl smime -encrypt -binary -text -aes256 -out db_backup.sql.gz.enc -outform DER mysqldump-secure.pub.pem
Use the key the decrypt
openssl smime -decrypt -in db_backup.sql.gz.enc -binary -inform DEM -inkey mysqldump-secure.priv.pem -out db_backup.sql.gz
Source: https://www.everythingcli.org/secure-mysqldump-script-with-encryption-and-compression/