3

How to sync staging and production database? I have staging database and i want to sync it with production database. Production database contains new customers and sales order. I dont want to replace customers and sales orders tables. What is the correct way to import staging database into production database without replacing orders and new customers.

** I know there are lot of magento stores and every one is dealing with same kind of situation.Please share correct way of doing this. Thanks

1
  • I know this post is several years old, I would like to know if this is a workable solution. This remains a problem. How do you synchronise data between production and staging environments after you have made changes? i.e. the difference between the staging and production server? to account for newer sales data that has occurred on the production store since. thanks
    – user93733
    Commented Dec 13, 2023 at 12:34

1 Answer 1

4

It is possible to do this through the magerun2 command db:dump which makes it possible to strip tables from your database dump.

Below a small description about the Strip option (Use the --help flag for more information)

Strip option
  If you like to skip data of some tables you can use the --strip option.
  The strip option creates only the structure of the defined tables and
  forces `mysqldump` to skip the data.

  Separate each table to strip by a space.
  You can use wildcards like * and ? in the table names to strip multiple
  tables. In addition you can specify pre-defined table groups, that start
  with an

  Example: "dataflow_batch_export unimportant_module_* @log

     $ n98-magerun.phar db:dump --strip="@stripped"


Available Table Groups
  @admin         Admin tables.
  @log           Log tables.
  @sessions      Database session tables.
  @stripped      Standard definition for a stripped dump (logs, sessions).
  @sales         Sales data (orders, invoices, creditmemos etc).
  @quotes        Cart (quote) data.
  @customers     Customer data - Should not be used without @sales.
  @trade         Current trade data (customers and orders). You usally do not
                 want those in developer systems..
  @development   Removes logs and trade data so developers do not have to work
                 with real customer data.
  @ee_changelog  Changelog tables of new indexer since EE 1.13.
  @search        Search related tables.
  @idx           Tables with _idx suffix.
3
  • correct me if i am wrong. Using this command do i need to first replace production database with staging database so that our staging database remains updated (with all customers and orders etc). Then i will make changes (add/update/remove products or edit configurations ,change shipping etc) in staging database . After that i dump staging database(--by skipping orders and customers tables) and import it in production (live) database.
    – Ashar Riaz
    Commented Dec 3, 2018 at 12:25
  • Theoretically speaking I think so. But I always recommend to create a full database backup of your product (live) database
    – Mr. Lewis
    Commented Dec 3, 2018 at 12:43
  • yes we will create backup before any change in database. I will try your solution and will accept your answer if everything works good. If possible please add some more steps of using magerun2. thanks
    – Ashar Riaz
    Commented Dec 3, 2018 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.