Create proper database dumps for Magento 2

When developing a Magento2 you might be needing database dumps from time to time from the production system. Normally you either dump the complete database - which, to me, bring a lot of negative side effects:

  • Size: Depending on the shop and the logging settings, the tables can grow up to multiple gigabytes.
  • Sensitive (customer) data: Getting all the (hashed) passwords, addresses and names from customers does not feel like a good idea. Depending on the companies compliance guideline you may not even allowed to have them.
  • Old/outdated data: Tables with logs or reports that are not necessary for your local development.

Instead of now writing your own script to dump only the files you need and exclude those, you don't want, just use the fantastic n98-magerun2. To dump a database without logs, sessions, trade data, admin users and index idx tables use:

n98-magerun.phar db:dump --strip="@development @idx"

Check the extended documentation for further groups and how to create your own groups.