How to Strip Large Magento 2 Database Dump using N98-MAGERUN2
As a Magento 2 developer, you are frequently doing the setup of the production site into your local machine. The production database consists of live orders, live customers, and large amounts of logs and session data. These data are not needed for development. So it is very important to strip Magento 2 Database dump for two reasons
- To Fast import production database into local
- To Avoid accidentally email send to live customers
We all know that it is not easy to strip MySQL tables from Magento 2 database. As Magento 2 database tables are inter-related with each other using a foreign key. To easily strip the database we will use n98-magerun2. First, we will see how to install n98-magerun2.
To install n98-magerun2 run below command in your Linux terminal.
wget https://files.magerun.net/n98-magerun2.phar chmod +x ./n98-magerun2.phar ./n98-magerun2.phar --version
To Strip large database dump run one of the commands as per your need in the root path of your Magento 2 installation.
Strip customer data from Magento 2 Database Dump
n98-magerun2.phar db:dump --strip="@customers"
Strip order data from Magento 2 Database Dump
n98-magerun2.phar db:dump --strip="@trade"
Strip logs and sessions data from Magento 2 Database Dump
n98-magerun2.phar db:dump --strip="@stripped"
Strip all logs, sessions, admin users, orders, and customers together from Magento 2 Database Dump
n98-magerun2.phar db:dump --strip="@development"
We have seen different commands for strip production database and make it secure and small for development purposes. Apart from these commands, n98-magerun2 offers many other useful commands. You can check full list of commands here.