1

It is well-known that creating a bacpac on SQL Azure does not guarantee transactional consistency when doing an export of a live, changing database.

The accepted workaround is to create a snapshot of the database first, by copying it, and then doing an export.

This approach is pretty ridiculous, because it forces users to spend extra money for relational DB storage. In fact, in the older days of SQL Azure, databases were billed by the day, so creating daily bacpacs from production databases essentially used to double the costs (it's now billed by the hour, if I'm not mistaken).

However, my question is not about this. My question is as follows - if it is acceptable for me to have a transactionally inconsistent bacpac, is there any way of actually restoring (i.e. importing it)? The problem is simple - because some constraints are no longer satisfied, the import fails (say, with a FK exception). While the bacpac restore is nothing more than re-creating the DB from the schema, followed by bulk imports, the entire process is completely opaque and not much control is given to the user. However, since Azure SQL tools are always in flux, I would not be surprised if this became possible.

So, to recap, the question: given a potentially inconsistent bacpac (i.e. some constaints won't hold), is there a way (without writing tons of code) to import it into an on-premise database?

4

1 回答 1

1

尝试使用 BCP.exe 导入数据。

  1. bacpac 是一个 zip 文件。您可以通过将文件扩展名更改为 .zip 来打开 bacpac。所有数据都以 .bcp 文件格式捕获在“数据”文件夹中。
  2. 从 zip 文件中移出 Data 文件夹并将其保存以用于下面的步骤 4。
  3. 将 .zip 扩展名改回 .bacpac 并导入。它只创建一个带有模式的数据库。
  4. 使用 bcp.exe,将 .bcp 文件导入数据库中的表。 https://msdn.microsoft.com/en-us/library/ms162802.aspx
  5. 对数据不一致进行故障排除和修复。

如果您已经知道哪个表包含不一致的数据,则可以仅移出该表的 bcp 文件并使用 bcp 导入它们。

于 2015-07-21T20:05:25.083 回答