前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >有api 接口可以实现自动下载腾讯云Mysql慢日志么?

有api 接口可以实现自动下载腾讯云Mysql慢日志么?

原创
作者头像
邵聪 SHAO CONG
修改2020-03-10 18:14:29
3.2K0
修改2020-03-10 18:14:29
举报
文章被收录于专栏:牡丹园

接口查询慢查询日志: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)

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档