Call the DescribeBackupPlanList API operation to query backup plan details using the Data Disaster Recovery Python SDK.
Prerequisites
Before you begin, ensure that you have:
-
Python 3 installed. Run
python --versionto check. -
A Resource Access Management (RAM) user with AccessKey credentials and the
AliyunDBSFullAccessorAliyunDBSReadOnlyAccesspolicy attached. See Create a RAM user and grant permissions if you have not done this yet.
How it works
All examples in this topic use the alibabacloud_dbs20190306 SDK package to submit API requests to the Data Disaster Recovery service. The SDK reads credentials from environment variables, sends a DescribeBackupPlanList request, and returns a paginated JSON response containing your backup plan details.
Create a RAM user and grant permissions
Skip this section if you already have a RAM user with an AccessKey and the required permissions.
-
Go to the Users page in the RAM console and click Create User.
-
Set Logon Name to dbs-openapi-operator and Access Mode to Using permanent AccessKey to access.
-
Click OK. On the page that appears, save the AccessKey ID and AccessKey secret of the RAM user.
-
On the Users page, find the RAM user and click Add Permissions in the Actions column.
-
Enter
AliyunDBSin the search box, then select one of the following policies:Policy Permissions AliyunDBSFullAccessRead and write access. Allows purchasing, configuring, and managing backup plans. AliyunDBSReadOnlyAccessRead-only access. Allows viewing task details and configurations, but not making changes. To create a custom policy based on your business requirements, see Custom policies for Data Disaster Recovery.
-
Click Grant permissions.
Call the API
1. Install the SDK package
pip install alibabacloud_dbs20190306
Tip: Run this command inside a virtual environment to avoid dependency conflicts with other packages installed on your system:python -m venv .venv source .venv/bin/activate # Linux or macOS .venv\Scripts\activate # Windows pip install alibabacloud_dbs20190306
2. Set environment variables
The SDK reads your credentials from the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
Linux or macOS — Run the following commands, replacing the placeholders with your AccessKey ID and AccessKey secret:
export ALIBABA_CLOUD_ACCESS_KEY_ID=<your-access-key-id>
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<your-access-key-secret>
Windows — Add ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET to your system environment variables, then restart your system.
3. Get the sample code
-
Go to the DescribeBackupPlanList debugging page in OpenAPI Explorer.
-
On the Parameters tab, set Region to cn-hangzhou (or your target region).
-
On the SDK Sample Code tab, select Python and click Download Project.
-
Extract the package and go to the
alibabacloud_sampledirectory.
4. Run the sample code
python sample.py
A successful response looks similar to this:
{
"headers": {
"date": "Mon, 17 Jun 2024 07:22:04 GMT",
"content-type": "application/json;charset=utf-8",
"content-length": "1064",
"connection": "keep-alive",
"keep-alive": "timeout=25",
"vary": "Accept-Encoding",
"access-control-allow-origin": "*",
"access-control-expose-headers": "*",
"x-acs-request-id": "4C4073F2-35A9-5819-88F1-C018A871****",
"x-acs-trace-id": "3c79c1be14f6f17be6aaa9af0f02****",
"etag": "1Jukbw3tBgZiZxgb8TVR****"
},
"statusCode": 200,
"body": {
"HttpStatusCode": 200,
"Items": {
"BackupPlanDetail": [
{
"BackupGatewayId": 16****,
"BackupMethod": "physical",
"BackupObjects": "[]",
"BackupPeriod": "SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY",
"BackupPlanCreateTime": 1718606018000,
"BackupPlanId": "dbsqe3w3vxq****",
"BackupPlanName": "DBS-csyl-L-3",
"BackupPlanStatus": "init",
"BackupRetentionPeriod": 730,
"BackupStartTime": "12:00",
"BackupStorageType": "system",
"DuplicationArchivePeriod": 0,
"DuplicationInfrequentAccessPeriod": 0,
"EnableBackupLog": true,
"InstanceClass": "medium",
"OSSBucketName": "dbs-backup-137383785969****-cn-hangzhou-qxl0qf4g****",
"OSSBucketRegion": "cn-hangzhou",
"OpenBackupSetAutoDownload": false,
"ResourceGroupId": "rg-acfmz7u4zzr****",
"SourceEndpointDatabaseName": "",
"SourceEndpointInstanceID": "",
"SourceEndpointInstanceType": "agent",
"SourceEndpointIpPort": "121.XX.XXX.171:3306",
"SourceEndpointRegion": "cn-hangzhou",
"SourceEndpointUserName": "root"
}
]
},
"PageNum": 0,
"PageSize": 30,
"RequestId": "4C4073F2-35A9-5819-88F1-C018A871****",
"Success": true,
"TotalElements": 1,
"TotalPages": 1
}
}
Key response fields:
| Field | Description |
|---|---|
BackupPlanStatus |
Current status of the backup plan. init means the plan has been created but not yet started. |
BackupRetentionPeriod |
How long backups are retained, in days. In this example, 730 days (2 years). |
BackupMethod |
Backup type. physical means a physical backup at the storage level. |
BackupPeriod |
Days of the week on which backups run. |
BackupStartTime |
Time of day when the backup starts. |
EnableBackupLog |
Whether log backup is enabled for point-in-time recovery. |
TotalElements |
Total number of backup plans in the response. Use with PageNum and PageSize for pagination. |
What's next
-
Read the full DescribeBackupPlanList API reference for all supported request parameters and response fields.
-
Browse the list of all Data Disaster Recovery API operations: 2019-03-06 version or 2021-01-01 version.
-
Use SDKs for other languages from the Data Disaster Recovery SDK page.