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. Data フォルダーを zip ファイルから移動し、以下の手順 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 に答える