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

Options:

  • -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)