Microsoft结构镜像公共 REST API

Fabric 镜像的公共 API 由两个类别组成:(1)Fabric 镜像数据库项的 CRUD 操作 和 (2)启动/停止和监视操作。 在 Microsoft Fabric REST API 参考 中,可以找到 Microsoft Fabric REST API 的主要联机参考文档。

注释

这些 REST API 不适用于 Azure Databricks 中的镜像数据库。

创建镜像数据库

REST API - 项 - 创建镜像数据库

在创建镜像数据库之前,需要相应的数据源连接。 如果还没有连接,请参阅 使用门户创建新连接 ,并在以下定义中使用该连接 ID。 还可以参考 创建新的连接 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 定义示例如下所示。 有关镜像数据库项定义的详细信息,包括定义结构的细分,请参阅 镜像数据库项定义。 还可以通过调用 Get 镜像数据库定义 API 来引用现有的镜像数据库定义

重要

若要从 Azure SQL 数据库、Azure SQL 托管实例、Azure Database for PostgreSQL 或 SQL Server 2025 镜像数据,还需要在开始镜像之前执行以下作:

  1. 启用 Azure SQL 逻辑服务器Azure SQL 托管实例Azure Database for PostgreSQLSQL Server 的系统分配托管标识(SAMI)。
  2. 向镜像数据库授予 SAMI 读取和写入 权限。 目前,您需要在 Fabric 门户中执行此操作。 或者,可以使用 “添加工作区角色分配 API”授予 SAMI 工作区角色。

注释

设置属性 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。 默认值为 7 天。 允许的值为介于 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

Microsoft Fabric .NET SDK 中提供了支持 Fabric 镜像的 .NET SDK。 版本需要 >= 1.0.0-beta.11。