接口查询慢查询日志:https://cloud.tencent.com/document/api/236/15845
上代码:
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.cdb.v20170320 import cdb_client, models
import re
import wget
import json
import os
# Please modify with your own Key.
secretId=""
secretKey=""
# The region of your instance locates in.
region="ap-xx"
# Seperate instance IDs with comma ","
instanceIds = ["cdb-xxx"]
# defind how many backups to get,i=offset,j=limit
i =
j =
# Get the result of DescribeSlowLogs
def GetUrlofSlowLogs(each_instance):
try:
cred = credential.Credential(secretId,secretKey)
httpProfile = HttpProfile()
httpProfile.endpoint = "cdb.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = cdb_client.CdbClient(cred, region, clientProfile)
req = models.DescribeSlowLogsRequest()
params = {"InstanceId":each_instance,"offset":i,"Limit":j}
param = json.dumps(params)
req.from_json_string(param)
resp = client.DescribeSlowLogs(req)
print(resp.to_json_string())
DescribeSlowLog = resp.to_json_string()
result = json.loads(DescribeSlowLog)
print result
return result
except TencentCloudSDKException as err:
print(err)
# start to download the slowlogs of each instance
for ID in instanceIds:
try:
slowlogresult = GetUrlofSlowLogs(ID)
for each_result in slowlogresult["Items"]:
url = each_result["IntranetUrl"]
notification="start to download the backup of " +ID
print(notification)
wget.download(url)
except TencentCloudSDKException as err:
print(err)