Restore woocommerce orders

2020-07-17 14:48发布

Recently my server team replaced my database and they put our previous Database . So we lost our order details of one day[particular day] . Now the server team give the backup that contain the lost day order details .

Now please tell how can i restore these orders ?

I cannot replace our database with the given backup , because today also we have orders .

Could anyone tell the step by step instruction ?

I Created a new database and uploaded backup .I understand that order are saved in wp_posts, and post meta .

So what i need to do ? , i export the all the order in that date from wp_posts,and post meta as sql file . Then just need to import it in to current database ? It make any problem ?

1条回答
叼着烟拽天下
2楼-- · 2020-07-17 15:29

This case is quite complicated, because as you can guess you have certainly in both databases (in your backup and actual databases) the same orders ID for different orders. When an order is made it populate the database tables "post", "postmeta" (and maybe some extra tables related to woocommerce that some wooCommerce plugins have created).

RETRIEVING THE MISSING DATA :
First in "post" backup table you have to find all "post_id" with a shop_order "post_type", starting at a specific date :
SELECT * FROM 'posts' WHERE 'post_date' > '2016-03-15 00:00:00' AND 'post_type' LIKE 'shop_order' ORDER BY 'post_id' ASC
(you have to set the correct beginning date and hour in here)

With all those post_id you are going to retrieve all the related data in "postmeta" table:
SELECT * FROM 'postmeta' WHERE 'post_id' > 2059 ORDER BY 'meta_id' ASC
(you have to replace post_id "2059" by your corresponding real one… )

PREPARING NEW DATA TO INSERT :
For "posts" table, you will have to shift all the different ID numbers for "post_id", before inserting them in your actual database, with new non existing yet values depending on the IDs already used by your actual database.

For "postmeta" table, you will have to replace all old "post_id" with the new values just generated in your "posts" table.

You will have to put your shop in maintenance mode to avoid new orders (for example with this free Maintenance Mode plugin)

You have to be used to MySQL and i think it's better to test all in a duplicated version of your webshop. Make backups before…

EDIT

Your website and your database are quiet heavy as you say in this wordpress.stackexchange post 10 Gb for your website and 2 Gb for the database.

THE QUICKEST AND EASY WAY:
So may be the best option is to create a new database on the same server importing the backup with the missed orders. Once done you can do the steps below
1) Put your webshop in maintenance mode (for example with this free Maintenance Mode plugin).
2) Make a backup of your database (just in case).
3) in your wp-config.php file change the database (to the old one with missed orders).
4) Immediately activate and Enable Maintenance Mode plugin.
5) Install WooCommerce Simply Order Export plugin and enable it.
6) Export your one day missing orders data as CSV or XML file.
7) in your wp-config.php file change the database (to the actual one with all new orders).
8) Enable WooCommerce Simply Order Export and import the CSV (or XML) file.
8) Disable WooCommerce Simply Order Export and Maintenance Mode plugins (and delete them if you want).

You are done!
Thanks to Mehul Gohil in that post

Regards

查看更多
登录 后发表回答