共用方式為


Microsoft Fabric 鏡像公用 REST API

Fabric 鏡像的公用 API 包含兩個類別:(1) Fabric 鏡像資料庫項目的 CRUD 作業 ,以及 (2) 啟動/停止和監視作業。 如需 Microsoft Fabric REST API 的主要線上參考檔,請參閱 Microsoft Fabric REST API 參考

備註

這些 REST API 不適用於來自 Azure Databricks 的鏡像資料庫。

建立鏡像資料庫

REST API - 項目 - 建立鏡像資料庫

在建立鏡像資料庫之前,需要對應的資料來源連線。 如果您還沒有連線,請參閱使用 入口網站建立新連線 ,並在下列定義中使用該連線識別碼。 您也可以參閱建立 新的連線 REST API ,以使用 Fabric REST API 建立新的連線。

範例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases

身體:

{
    "displayName": "Mirrored database 1",
    "description": "A mirrored database description",
    "definition": {
        "parts": [
            {
                "path": "mirroring.json",
                "payload": "eyAicHJvcGVydGllcy..WJsZSIgfSB9IH0gXSB9IH0",
                "payloadType": "InlineBase64"
            }
        ]
    }
}

payload先前 JSON 本文中的屬性是 Base64 編碼。 您可以使用 Base64 編碼和解碼 進行編碼。

原始 JSON 定義範例如下。 如需鏡映資料庫專案定義的詳細資訊,包括定義結構的細分,請參閱 鏡映資料庫專案定義。 您也可以呼叫 取得鏡像資料庫定義 API 來參考現有鏡像資料庫的定義。

這很重要

若要鏡像來自 Azure SQL 資料庫、Azure SQL 受控執行個體、適用於 PostgreSQL 的 Azure 資料庫或 SQL Server 2025 的資料,您也必須在開始鏡像之前執行下列動作:

  1. 啟用你的 Azure SQL 邏輯伺服器Azure SQL 管理實例Azure Database for PostgreSQLSQL Server 的管理身份。
  2. 授予受管理身份的 讀寫 權限給鏡像資料庫。 目前,您必須在 Fabric 入口網站上執行此動作。 或者,您也可以使用 Add Workspace Role Assignment API 授權管理身份工作區角色。

備註

設定屬性 deafultSchema 以保留鏡像資料庫中的來源結構描述階層。

複製整個資料庫的 JSON 定義範例

若要鏡像來源資料庫中的所有資料表:

{
    "properties": {
        "source": {
            "type": "<your source type>",
            "typeProperties": {
                "connection": "a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
                "database": "xxxx"
            }
        },
        "target": {
            "type": "MountedRelationalDatabase",
            "typeProperties": {
                "defaultSchema": "xxxx",
                "format": "Delta"
            }
        }
    }
}

複寫指定資料表的 JSON 定義範例

若要鏡像來源資料庫中的選擇性資料表,您可以指定 mountedTables 屬性,如下列範例所示。

{
    "properties": {
        "source": {
            "type": "<your source type>",
            "typeProperties": {
                "connection": "a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
                "database": "xxxx"
            }
        },
        "target": {
            "type": "MountedRelationalDatabase",
            "typeProperties": {
                "defaultSchema": "xxxx",
                "format": "Delta"
            }
        },
        "mountedTables": [
            {
                "source": {
                    "typeProperties": {
                        "schemaName": "xxxx",
                        "tableName": "xxxx"
                    }
                }
            }
        ]
    }
}

回應 201:

{ 
    "id": "<mirrored database ID>", 
    "type": "MirroredDatabase", 
    "displayName": "Mirrored database 1", 
    "description": "A mirrored database description", 
    "workspaceId": "<your workspace ID>" 
} 

刪除鏡像資料庫

REST API - 項目 - 刪除鏡像資料庫

範例:

DELETE https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases/<mirrored database ID>

回應 200:(沒有屍體)

取得鏡像資料庫

REST API - 項目 - 取得鏡像資料庫

範例:

GET https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases/<mirrored database ID>

回應 200:

{
    "displayName": "Mirrored database 1",
    "description": "A mirrored database description.",
    "type": "MirroredDatabase",
    "workspaceId": "<your workspace ID>",
    "id": "<mirrored database ID>",
    "properties": {
        "oneLakeTablesPath": "https://onelake.dfs.fabric.microsoft.com/<your workspace ID>/<mirrored database ID>/Tables",
        "sqlEndpointProperties": {
            "connectionString": "xxxx.xxxx.fabric.microsoft.com",
            "id": "b1b1b1b1-cccc-dddd-eeee-f2f2f2f2f2f2",
            "provisioningStatus": "Success"
        },
        "defaultSchema": "xxxx"
    }
}

取得鏡像資料庫定義

REST API - 項目 - 取得鏡像資料庫定義

範例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases/<mirrored database ID>/getDefinition

回應 200:

{ 
    "definition": { 
        "parts":[ 
            { 
                "path": "mirroring.json", 
                "payload": "eyAicHJvcGVydGllcy..WJsZSIgfSB9IH0gXSB9IH0", 
                "payloadType": "InlineBase64" 
            } 
        ] 
    } 
} 

列出鏡像資料庫

REST API - 項目 - 列出鏡像資料庫

範例:

GET https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases

回應 200:

{ 
    "value": [ 
        {
            "displayName": "Mirrored database 1",
            "description": "A mirrored database description.",
            "type": "MirroredDatabase",
            "workspaceId": "<your workspace ID>",
            "id": "<mirrored database ID>",
            "properties": {
                "oneLakeTablesPath": "https://onelake.dfs.fabric.microsoft.com/<your workspace ID>/<mirrored database ID>/Tables",
                "sqlEndpointProperties": {
                    "connectionString": "xxxx.xxxx.fabric.microsoft.com",
                    "id": "b1b1b1b1-cccc-dddd-eeee-f2f2f2f2f2f2",
                    "provisioningStatus": "Success"
                },
                "defaultSchema": "xxxx"
            }
        }
    ] 
} 

更新鏡像資料庫

REST API - 項目 - 更新鏡像資料庫

範例:

PATCH https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases/<mirrored database ID>

身體:

{
    "displayName": "MirroredDatabase's New name",
    "description": "A new description for mirrored database."
}

回應 200:

{
    "displayName": "MirroredDatabase's New name",
    "description": "A new description for mirrored database.",
    "type": "MirroredDatabase",
    "workspaceId": "<your workspace ID>",
    "id": "<mirrored database ID>"
}

更新鏡映資料庫定義

REST API - 項目 - 更新鏡像資料庫定義

範例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases/<mirrored database ID>/updateDefinition

身體:

{ 
  "definition": { 
    "parts": [ 
      { 
        "path": "mirroring.json", 
        "payload": "eyAicHJvcGVydGllcy..WJsZSIgfSB9IH0gXSB9IH0", 
        "payloadType": "InlineBase64" 
      } 
    ] 
  } 
}

回應 200:(沒有屍體)

先前 JSON 本文中的承載屬性是 Base64 編碼。 您可以使用 Base64 編碼和解碼 進行編碼。

備註

此 API 支援透過重新整理 mountedTables 屬性來新增/移除資料表。 也支援更新來源連線ID、資料庫名稱和預設模式(這三個屬性只有在 取得鏡像狀態 API傳回 Initialized/Stopped時才能更新)。

設定資料保留

您可以使用屬性來設定retentionInDays。 預設值為七天。 允許的值介於 1 到 30 之間的整數。

Base64編碼前的JSON定義範例:

{
    "properties": {
        "source": {...},
        "target": {
            "type": "MountedRelationalDatabase",
            "typeProperties": {
                "defaultSchema": "xxxx",
                "format": "Delta",
                "retentionInDays": 1
            }
        }
    }
}

取得鏡像狀態

REST API - 鏡像 - 取得鏡像狀態

此 API 會傳回鏡映資料庫執行個體的狀態。 可用狀態的清單會在 MirroringStatus 的值處提供。

範例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases/<mirrored database ID>/getMirroringStatus

回應 200:

{
    "status": "Running"
}

開始鏡像

REST API - 鏡像 - 開始鏡像

範例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases/<mirrored database ID>/startMirroring

回應 200:(沒有屍體)

備註

在上述取得 鏡像狀態 API 傳回 Initializing 狀態時,無法啟動鏡像。

取得資料表鏡射狀態

REST API - 鏡像 - 取得資料表鏡像狀態

如果鏡像已啟動,且 取得鏡像狀態 API 傳回 Running 狀態,則此 API 會傳回資料表複寫的狀態和計量。

範例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases/<mirrored database ID>/getTablesMirroringStatus

回應 200:

{
    "continuationToken": null,
    "continuationUri": null,
    "data": [
        {
            "sourceSchemaName": "dbo",
            "sourceTableName": "test",
            "status": "Replicating",
            "metrics": {
                "processedBytes": 1247,
                "processedRows": 6,
                "lastSyncDateTime": "2024-10-08T05:07:11.0663362Z"
            }
        }
    ]
}

停止鏡像

REST API - 鏡像 - 停止鏡像

範例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases/<mirrored database ID>/stopMirroring

回應 200:(沒有屍體)

備註

停止鏡像後,可以呼叫 取得鏡像狀態 API來查詢鏡像狀態。

Microsoft Fabric .NET SDK

支援 Fabric 鏡像的 .NET SDK 可在 Microsoft Fabric .NET SDK 取得。 版本必須為 >= 1.0.0-beta.11。