Skip to content

Adds shorthands in WP-CLI to easily create database dumps without sensitive data, i.e. customers, users and/or orders.

Notifications You must be signed in to change notification settings

Dan0sz/strip-db-dump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WP-CLI Strip Database Dump

This is a tiny plugin, which adds shorthands to WP-CLI which allows you to easily create database dumps and exclude sensitive data.

The following options are available:

  • --users: excludes the wp_users and wp_usermeta tables.
  • --customers: excludes Customer related tables for supported 3rd party plugins.
  • --orders: excludes Order related tables for supported 3rd party plugins.
  • --all: exclude all of the above.

After running the command, 2 separate database exports are created:

  1. [your-filename]-1.sql containing all tables where data should be retained.
  2. [your-filename]-2.sql containing all tables where all data should be stripped.

Important

The created DB dumps must be imported in the provided order.

Usage

To create a database that excludes orders, customers and users and save it one directory up from the current directory, run it as follows:

wp strip-db dump ../stripped-db-dump.sql --all

To just strip customer data and store the dump in the current directory, run:

wp strip-db dump stripped-dump --customers

Note

It's not required to append a file extension to the filename argument.

If no filename is provided, a random one will be generated and saved in WordPress' root directory.

Important

When the --users parameter is added to the command, the users table will be empty when importing it to your database. This means you need to create at least a new administrator user after importing the generated table. This can be done using the following WP-CLI command: wp user create username [email protected] --role=administrator.

3rd Party Plugin Support

The plugin currently removes sensitive data (i.e. any data containing personal information) for the following plugins:

  • AffiliateWP
  • Easy Digital Downloads
  • WooCommerce
  • WPForms

Tip

If You want this plugin to support more 3rd party plugins, feel free to submit a pull request!

As of v1.1.1 adding support for additional 3rd party plugins is easy. It's a matter of adding a class to src/Compatibility and implementing this plugin's different interfaces along with their required methods. If your plugin requires truncating of Orders and Customers tables, your Compatibility class should implement the CustomersCompatibilityInterface and the OrdersCompatibilityInterface.

Each method should return an array of corresponding table names without prefix! Then, add the new class to the corresponding handlers in Main and you're ready to submit your PR! :-)

Installation

Download the latest release from the Releases page (or click the link) and install it in WordPress:

  1. Navigate to your Administrator area,
  2. Go to Plugins >> Add New Plugin
  3. Click the Upload Plugin button in the top-left of the screen
  4. Browse... to the ZIP file and install it by clicking Install Now.

About

Adds shorthands in WP-CLI to easily create database dumps without sensitive data, i.e. customers, users and/or orders.

Topics

Resources

Stars

Watchers

Forks

Languages