M
M
Magi2016-05-20 12:01:20
Encryption
Magi, 2016-05-20 12:01:20

How to properly encrypt mysqldump output?

I'm trying to pack the output like this
/usr/bin/mysqldump --opt -v --databases $bd_name -u$user -p$password | bzip2 -9 > backup-$(date +%d-%b-%Y).tar.bz2
We also need to add encryption here.
But for some reason the resulting file is not unpacked afterwards. Tell me how to pack with encryption with one command?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2016-05-20
@fox_12

Packing:

$ mysqldump --opt -usome_user -psome_pass mysql | openssl enc -aes-256-cbc | bzip2 -9 > backup.bz2
enter aes-256-cbc encryption password:mysqldump: 
[Warning] Using a password on the command line interface can be insecure.

Verifying - enter aes-256-cbc encryption password:

Let's see what's packed there:
$ bzip2 -d backup.bz2 
$ head backup
Salted__????,?z"?1f????	9???>?>??n??q?/?{,??}E2'4*W?e?,+N???
????i??"??Lc[?-??Io?`??3???%fnXf????s??5A<?hz?}...

unpack with decryption:
$ bzip2 -d -c backup.bz2 | openssl enc -aes-256-cbc -d > out.sql
enter aes-256-cbc decryption password:

Checking the result:
$ head out.sql 
-- MySQL dump 10.13  Distrib 5.7.10, for osx10.11 (x86_64)
--
-- Host: localhost    Database: mysql
-- ------------------------------------------------------
-- Server version	5.7.10

/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;
/*!40101 SET @[email protected]@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

M
Magi, 2016-05-20
@Magi

I tried it, it works, but compressed file is 4990492 bytes, decompressed is 4967569. Looks like bzip2 doesn't work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question