This topic describes how to use Database Backup (DBS) SDK for Python to call the DescribeBackupPlanList operation to query the details of a backup schedule.
View API documentation
Before you call the DescribeBackupPlanList operation, we recommend that you read the documentation about the API operation to learn about the parameters and permissions that are required to call the API operation. For more information, see List of operations by function (2019-03-06) or List of operations by function (2021-01-01).
Create a RAM user and grant permissions to the RAM user
If you have created a Resource Access Management (RAM) user and granted permissions to the RAM user, skip this step.
Create a RAM user.
Log on to the RAM console, go to the Users page, and then click Create User.
Set the Logon Name parameter to dbs-openapi-operator and select OpenAPI Access for the Access Mode parameter.
Click OK. After the RAM user is created, save the AccessKey ID and AccessKey secret of the RAM user.
Grant permissions to the RAM user.
On the Users page, find the RAM user and click Add Permissions in the Actions column.
Enter
AliyunDBS
in the search box and select the AliyunDBSFullAccess policy.NoteThe AliyunDBSFullAccess policy contains the read and write permissions on DBS. The RAM user to whom the policy is attached can perform multiple operations on DBS. For example, the RAM user can purchase, configure, and manage DBS backup schedules. The AliyunDBSReadOnlyAccess policy contains the read permissions on DBS. The RAM user to whom the policy is attached can view the information about all DBS tasks within the Alibaba Cloud account, including task details and configurations. However, the RAM user cannot perform changes on the tasks.
You can also create custom policies based on your business requirements. For more information, see DBS custom policies.
Click Grant permissions.
Call the API
This section describes how to use DBS SDK for Python to call API operations. You can use SDKs for other programming languages in a similar way. For more information, see DBS SDK.
Install Python
Download and install Python 3. If you have installed Python, you can run the python --version
command to view the Python version.
Configure environment variables
This section describes how to configure the ALIBABA_CLOUD_ACCESS_KEY_ID
and ALIBABA_CLOUD_ACCESS_KEY_SECRET
environment variables.
If you use a Linux or macOS operating system, replace
<ACCESS_KEY_ID>
and<ACCESS_KEY_SECRET>
in the following commands with your AccessKey ID and AccessKey secret. Then, run the commands in sequence on your device.export ALIBABA_CLOUD_ACCESS_KEY_ID=<ACCESS_KEY_ID> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET>
If you use a Windows operating system, create a file to add the
ALIBABA_CLOUD_ACCESS_KEY_ID
andALIBABA_CLOUD_ACCESS_KEY_SECRET
environment variables and specify your AccessKey ID and AccessKey secret by using the environment variables. Then, restart the Windows operating system.
Install dependencies
Run the following command on your device to install dependencies:
pip install alibabacloud_dbs20190306
Download the sample code
Go to the debugging page of the DescribeBackupPlanList operation in OpenAPI Explorer.
On the Parameters tab on the left, configure the request parameters. In this example, the Region parameter is set to cn-hangzhou.
On the SDK Sample Code tab on the right, select Python for the Languages parameter and click Download Project to download the sample code package.
Decompress the package on your device and go to the alibabacloud_sample directory.
Run the sample code
Run the following command:
python sample.py
Sample response:
{
"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
}
}