Secure and compress backup streams. Learn to pipe backup output to tools like GPG and GZIP for encryption and storage efficiency.
mariadb-backup supports streaming to stdout with the --stream=xbstream option. This option allows easy integration with popular encryption and compression tools. Below are several examples.
The following example creates an AES-encrypted backup, protected with the password "mypass" and stores it in a file "backup.xb.enc":
To decrypt and unpack this backup into the current directory, the following command can be used:
This example compresses the backup without encrypting:
We can decompress and unpack the backup as follows:
This example adds a compression step before the encryption, otherwise looks almost identical to the previous example:
We can decrypt, decompress and unpack the backup as follow (note gzip -d in the pipeline):
7zip archiver is a popular utility (especially on Windows) that supports reading from standard output, with the --si option, and writing to stdout with the -so option, and can thus be used together with mariadb-backup.
Compressing backup with the 7z command line utility works as follows:
Uncompress and unpack the archive with
7z also has builtin AES-256 encryption. To encrypt the backup from the previous example using password SECRET, add -pSECRET to the 7z command line.
Compress
Decompress , unpack
Encryption
Decrypt, unpack
Most of the described tools also provide a way to enter a passphrase interactively (although 7zip does not seem to work well when reading input from stdin). Please consult documentation of the tools for more info.
By default files like xtrabackup_checkpoints are also written to the output stream only, and so would not be available for taking further incremental backups without prior extraction from the compressed or encrypted stream output file.
To avoid this these files can additionally be written to a directory that can then be used as input for further incremental backups using the --extra-lsndir=... option.
See also e.g: Combining incremental backups with streaming output
This page is licensed: CC BY-SA / Gnu FDL
mariadb-backup --user=root --backup --stream=xbstream | openssl enc -aes-256-cbc -k mypass > backup.xb.encopenssl enc -d -aes-256-cbc -k mypass -in backup.xb.enc | mbstream -xmariadb-backup --user=root --backup --stream=xbstream | gzip > backupstream.gzgunzip -c backupstream.gz | mbstream -xmariadb-backup --user=root --backup --stream=xbstream | gzip | openssl enc -aes-256-cbc -k mypass > backup.xb.gz.encopenssl enc -d -aes-256-cbc -k mypass -in backup.xb.gz.enc |gzip -d| mbstream -xmariadb-backup --user=root --backup --stream=xbstream | 7z a -si backup.xb.7z7z e backup.xb.7z -so |mbstream -xmariadb-backup --user=root --backup --stream=xbstream | zstd - -o backup.xb.zst -f -1zstd -d backup.xbstream.zst -c | mbstream -xmariadb-backup --user=root --backup --stream=xbstream | gpg -c --passphrase SECRET --batch --yes -o backup.xb.gpggpg --decrypt --passphrase SECRET --batch --yes backup.xb.gpg | mbstream -x