Skip to main content

joeri poesen / bio / blog / contact

Home / Articles / Howto: Drush sql-dump a Drupal database and compress the output with bzip2

Because I keep forgetting: here's a one-liner to immediately compress drush sql-dump output with bzip2. This'll work for any command that generates output, such as mysqldump and tar.

$ drush sql-dump | bzip2 > filename.bz2

If no option is provided, bzip2 assumes -c (compress).

Now, to decompress:

$ bzip2 -dkf filename.bz2


  • -d: decompress
  • -k: keep original archive file (otherwise bzip2 deletes it after decompressing)
  • -f: force-overwrite output file (otherwise bzip2 will complain about output file already existing)


You can also 'bunzip2' to decompress the file.

Also see helpful commands like 'bzgrep', and 'bzcat' (among others) as wrappers around grep and cat to avoid having to decompress the file first. This is particularly useful if the file is really big when decompressed. Same works for gzip files with 'zgrep' and 'zcat'.

Add new comment