mysql - 恢复 woocommerce 订单

标签 mysql sql wordpress woocommerce orders

最近我的服务器团队更换了我的数据库,他们把我们以前的数据库 .所以我们丢失了一天[特定日期]的订单详细信息。现在服务器团队提供包含丢失日订单详细信息的备份。

现在请告诉我如何恢复这些订单?

我不能用给定的备份替换我们的数据库,因为今天我们也有订单。

任何人都可以告诉一步一步的说明吗?

我创建了一个新数据库并上传了备份。我知道订单保存在 wp_posts 和 post meta 中。

那我需要做什么? ,我从 wp_posts 导出该日期的所有订单,并将元数据发布为 sql 文件。然后只需要将它导入到当前数据库?它有什么问题吗?

最佳答案

这种情况非常复杂,因为您可以猜到,在两个数据库(在备份数据库和实际数据库中)中,不同订单的订单 ID 是相同的。 下订单后,它会填充数据库表“post”、“postmeta”(可能还有一些 wooCommerce 插件创建的与 woocommerce 相关的额外表)。

检索丢失的数据:
首先在“post”backup 表中,您必须找到所有具有shop_order“post_type”的“post_id”,从特定日期开始:
SELECT * FROM 'posts' WHERE 'post_date' > '2016-03-15 00:00:00' AND 'post_type' LIKE 'shop_order' ORDER BY 'post_id' ASC
(您必须在此处设置正确的开始日期和时间)

使用所有这些 post_id,您将检索“postmeta”表中的所有相关数据:
SELECT * FROM 'postmeta' WHERE 'post_id' > 2059 ORDER BY 'meta_id' ASC
(您必须将 post_id“2059”替换为您对应的真实编号……)

准备要插入的新数据:
对于“posts”表,在将它们插入实际数据库之前,您必须移动“post_id”的所有不同 ID 号,根据实际数据库已经使用的 ID 使用新的不存在的值。

对于“postmeta”表,您必须用刚刚在“posts”表中生成的新值替换所有旧的“post_id”。

您必须将您的商店置于维护模式以避免新订单(例如使用这个免费的 Maintenance Mode 插件)

您必须习惯使用 MySQL,我认为最好在您的网上商店的复制版本中测试所有内容。 在……之前进行备份

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

问候

关于mysql - 恢复 woocommerce 订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36234875/

相关文章:

sql - 如何写 "WHERE foo = ' bar' OR foo = 'baz' OR .. ."without repeating "foo"each

sql - 数据建模 - 如何处理两个相关的 "status"列?

PHP export MySQL to xml 非英文字符在浏览器中显示为 `?`

mysql - 如何在 MYSQL 服务器中使用单个 JOIN 语句更新两个表?

MySQL/SQL : Update with correlated subquery from the updated table itself

sql - 优化时间序列数据的 MIN/MAX 查询

sql - 如何在关系代数中表示 "not exists"?

css - wordpress网站中的主菜单背景颜色更改

php - 在给定类别中使用通配符搜索 WordPress 帖子中的特定句子并输出唯一结果

wordpress - 将 Wordpress 站点移动到 HTTPS