命名空间:microsoft.graph
为 M365 服务 SharePoint 创建保护策略。 策略将以状态创建 inactive 。 用户还可以在策略下提供保护单元的列表。
此 API 可用于以下国家级云部署。
| 全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
| ✅ |
❌ |
❌ |
❌ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
| 权限类型 |
最低特权权限 |
更高特权权限 |
| 委派(工作或学校帐户) |
BackupRestore-Configuration.ReadWrite.All |
不可用。 |
| 委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
| 应用程序 |
BackupRestore-Configuration.ReadWrite.All |
不可用。 |
HTTP 请求
POST /solutions/backupRestore/sharePointProtectionPolicies/
| 名称 |
说明 |
| Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
请求正文
创建 sharePointProtectionPolicy 对象时,可以指定以下属性。
| 属性 |
类型 |
说明 |
| displayName |
String |
SharePoint 保护策略的名称。 可选。 |
| siteProtectionUnits |
集合 (siteProtectionUnit) |
要添加到 sharePointProtectionPolicy 对象的 siteProtectionUnits 的集合。 必填。 有关 siteId 的格式,请参阅站点。 |
响应
如果成功,此方法在 201 Created 响应正文中返回响应代码和 sharePointProtectionPolicy 对象。
有关可能的错误响应的列表,请参阅 备份存储 API 错误响应。
示例
请求
以下示例显示了一个请求。
POST https://graph.microsoft.com/v1.0/solutions/backupRestore/sharePointProtectionPolicies
{
"displayName": "SharePoint Protection Policy",
"siteProtectionUnits": [
{
"siteId": "contoso.sharepoint.com,febad3c2-a7b2-454c-8910-272c7bcf78fc,ba7b70d0-8ba0-4cae-b19a-7cb8c739512f"
},
{
"siteId": "contoso.sharepoint.com/sites/marketing,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740"
},
{
"siteId": "contoso.sharepoint.com/sites/hr,3bfc861e-9a17-4a27-9562-3d8b26c81bb5,0271110f-634f-4300-a841-3a8a2e851851"
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new SharePointProtectionPolicy
{
DisplayName = "SharePoint Protection Policy",
SiteProtectionUnits = new List<SiteProtectionUnit>
{
new SiteProtectionUnit
{
SiteId = "contoso.sharepoint.com,febad3c2-a7b2-454c-8910-272c7bcf78fc,ba7b70d0-8ba0-4cae-b19a-7cb8c739512f",
},
new SiteProtectionUnit
{
SiteId = "contoso.sharepoint.com/sites/marketing,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740",
},
new SiteProtectionUnit
{
SiteId = "contoso.sharepoint.com/sites/hr,3bfc861e-9a17-4a27-9562-3d8b26c81bb5,0271110f-634f-4300-a841-3a8a2e851851",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Solutions.BackupRestore.SharePointProtectionPolicies.PostAsync(requestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewSharePointProtectionPolicy()
displayName := "SharePoint Protection Policy"
requestBody.SetDisplayName(&displayName)
siteProtectionUnit := graphmodels.NewSiteProtectionUnit()
siteId := "contoso.sharepoint.com,febad3c2-a7b2-454c-8910-272c7bcf78fc,ba7b70d0-8ba0-4cae-b19a-7cb8c739512f"
siteProtectionUnit.SetSiteId(&siteId)
siteProtectionUnit1 := graphmodels.NewSiteProtectionUnit()
siteId := "contoso.sharepoint.com/sites/marketing,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740"
siteProtectionUnit1.SetSiteId(&siteId)
siteProtectionUnit2 := graphmodels.NewSiteProtectionUnit()
siteId := "contoso.sharepoint.com/sites/hr,3bfc861e-9a17-4a27-9562-3d8b26c81bb5,0271110f-634f-4300-a841-3a8a2e851851"
siteProtectionUnit2.SetSiteId(&siteId)
siteProtectionUnits := []graphmodels.SiteProtectionUnitable {
siteProtectionUnit,
siteProtectionUnit1,
siteProtectionUnit2,
}
requestBody.SetSiteProtectionUnits(siteProtectionUnits)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
sharePointProtectionPolicies, err := graphClient.Solutions().BackupRestore().SharePointProtectionPolicies().Post(context.Background(), requestBody, nil)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
SharePointProtectionPolicy sharePointProtectionPolicy = new SharePointProtectionPolicy();
sharePointProtectionPolicy.setDisplayName("SharePoint Protection Policy");
LinkedList<SiteProtectionUnit> siteProtectionUnits = new LinkedList<SiteProtectionUnit>();
SiteProtectionUnit siteProtectionUnit = new SiteProtectionUnit();
siteProtectionUnit.setSiteId("contoso.sharepoint.com,febad3c2-a7b2-454c-8910-272c7bcf78fc,ba7b70d0-8ba0-4cae-b19a-7cb8c739512f");
siteProtectionUnits.add(siteProtectionUnit);
SiteProtectionUnit siteProtectionUnit1 = new SiteProtectionUnit();
siteProtectionUnit1.setSiteId("contoso.sharepoint.com/sites/marketing,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740");
siteProtectionUnits.add(siteProtectionUnit1);
SiteProtectionUnit siteProtectionUnit2 = new SiteProtectionUnit();
siteProtectionUnit2.setSiteId("contoso.sharepoint.com/sites/hr,3bfc861e-9a17-4a27-9562-3d8b26c81bb5,0271110f-634f-4300-a841-3a8a2e851851");
siteProtectionUnits.add(siteProtectionUnit2);
sharePointProtectionPolicy.setSiteProtectionUnits(siteProtectionUnits);
SharePointProtectionPolicy result = graphClient.solutions().backupRestore().sharePointProtectionPolicies().post(sharePointProtectionPolicy);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const sharePointProtectionPolicy = {
displayName: 'SharePoint Protection Policy',
siteProtectionUnits: [
{
siteId: 'contoso.sharepoint.com,febad3c2-a7b2-454c-8910-272c7bcf78fc,ba7b70d0-8ba0-4cae-b19a-7cb8c739512f'
},
{
siteId: 'contoso.sharepoint.com/sites/marketing,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740'
},
{
siteId: 'contoso.sharepoint.com/sites/hr,3bfc861e-9a17-4a27-9562-3d8b26c81bb5,0271110f-634f-4300-a841-3a8a2e851851'
}
]
};
await client.api('/solutions/backupRestore/sharePointProtectionPolicies')
.post(sharePointProtectionPolicy);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\SharePointProtectionPolicy;
use Microsoft\Graph\Generated\Models\SiteProtectionUnit;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SharePointProtectionPolicy();
$requestBody->setDisplayName('SharePoint Protection Policy');
$siteProtectionUnitsSiteProtectionUnit1 = new SiteProtectionUnit();
$siteProtectionUnitsSiteProtectionUnit1->setSiteId('contoso.sharepoint.com,febad3c2-a7b2-454c-8910-272c7bcf78fc,ba7b70d0-8ba0-4cae-b19a-7cb8c739512f');
$siteProtectionUnitsArray []= $siteProtectionUnitsSiteProtectionUnit1;
$siteProtectionUnitsSiteProtectionUnit2 = new SiteProtectionUnit();
$siteProtectionUnitsSiteProtectionUnit2->setSiteId('contoso.sharepoint.com/sites/marketing,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740');
$siteProtectionUnitsArray []= $siteProtectionUnitsSiteProtectionUnit2;
$siteProtectionUnitsSiteProtectionUnit3 = new SiteProtectionUnit();
$siteProtectionUnitsSiteProtectionUnit3->setSiteId('contoso.sharepoint.com/sites/hr,3bfc861e-9a17-4a27-9562-3d8b26c81bb5,0271110f-634f-4300-a841-3a8a2e851851');
$siteProtectionUnitsArray []= $siteProtectionUnitsSiteProtectionUnit3;
$requestBody->setSiteProtectionUnits($siteProtectionUnitsArray);
$result = $graphServiceClient->solutions()->backupRestore()->sharePointProtectionPolicies()->post($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.BackupRestore
$params = @{
displayName = "SharePoint Protection Policy"
siteProtectionUnits = @(
@{
siteId = "contoso.sharepoint.com,febad3c2-a7b2-454c-8910-272c7bcf78fc,ba7b70d0-8ba0-4cae-b19a-7cb8c739512f"
}
@{
siteId = "contoso.sharepoint.com/sites/marketing,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740"
}
@{
siteId = "contoso.sharepoint.com/sites/hr,3bfc861e-9a17-4a27-9562-3d8b26c81bb5,0271110f-634f-4300-a841-3a8a2e851851"
}
)
}
New-MgSolutionBackupRestoreSharePointProtectionPolicy -BodyParameter $params
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.share_point_protection_policy import SharePointProtectionPolicy
from msgraph.generated.models.site_protection_unit import SiteProtectionUnit
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SharePointProtectionPolicy(
display_name = "SharePoint Protection Policy",
site_protection_units = [
SiteProtectionUnit(
site_id = "contoso.sharepoint.com,febad3c2-a7b2-454c-8910-272c7bcf78fc,ba7b70d0-8ba0-4cae-b19a-7cb8c739512f",
),
SiteProtectionUnit(
site_id = "contoso.sharepoint.com/sites/marketing,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740",
),
SiteProtectionUnit(
site_id = "contoso.sharepoint.com/sites/hr,3bfc861e-9a17-4a27-9562-3d8b26c81bb5,0271110f-634f-4300-a841-3a8a2e851851",
),
],
)
result = await graph_client.solutions.backup_restore.share_point_protection_policies.post(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
响应
以下示例显示了相应的响应。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-Location: https://graph.microsoft.com/v1.0/solutions/backupRestore/protectionPolicies/b218eb4a-ea72-42bd-8f0b-d0bbf794bec7
{
"@odata.context": " /solutions/backupRestore/$metadata#sharePointProtectionPolicies/$entity",
"id": "b218eb4a-ea72-42bd-8f0b-d0bbf794bec7",
"displayName": "SharePoint Protection Policy",
"status": "inactive",
"createdBy": {
"application": {
"id": "1fec8e78-bce4-4aaf-ab1b-5451cc387264",
"displayName": "Microsoft Enhanced Restore"
},
"user": {
"email": "User1@contoso.com",
"id": "845457dc-4bb2-4815-bef3-8628ebd1952e",
"displayName": "User1"
}
},
"createdDateTime": "2015-06-19T12:01:03.45Z",
"lastModifiedBy": {
"application": {
"id": "1fec8e78-bce4-4aaf-ab1b-5451cc387264",
"displayName": "Microsoft Enhanced Restore"
},
"user": {
"email": "User2@constoso.com",
"id": "845457dc-4bb2-4815-bef3-8628ebd1952e",
"displayName": "User2"
}
},
"lastModifiedDateTime": "2015-06-19T12:01:03.45Z",
"retentionSettings": [
{
//Keep the per 10 minute copies for 14 days
"interval": "R/PT10M",
"period": "P2W"
},
{
//Keep the per week copies for 1 year
"interval": "R/P1W",
"period": "P1Y"
}
]
}