python自动备份阿里云数据库binlog

两盒软妹~` 提交于 2019-12-03 11:00:33
#coding:utf8from aliyunsdkcore import clientfrom aliyunsdkrds.request.v20140815 import DescribeBackupsRequestfrom aliyunsdkrds.request.v20140815 import DescribeBinlogFilesRequestimport jsonimport urllibimport datetimeimport osdef binlogmobile(db_instanceid):        today_time = datetime.datetime.now()        date1 = datetime.datetime.strftime(today_time, '%Y-%m-%d')  # +‘T00:00:00Z‘        yes_time = today_time + datetime.timedelta(days=-1)        date2 = datetime.datetime.strftime(yes_time,'%Y-%m-%d')  #  +‘T00:00:00Z‘        start_date = date2        end_date = date1        startdate = start_date+'T00:00:00Z'        enddate = end_date+'T00:00:00Z'        cur_dir = '/logs/mysql/mobile/'        folder_name = date1        os.mkdir(os.path.join(cur_dir, folder_name))        clt = client.AcsClient('accesskeyid','密码','cn-beijing')        request = DescribeBinlogFilesRequest.DescribeBinlogFilesRequest()        request.set_accept_format('json')        request.set_action_name('DescribeBinlogFiles')        request.set_DBInstanceId(db_instanceid)        request.set_StartTime(startdate)        request.set_EndTime(enddate)        result = clt.do_action(request)        s=json.loads(result)        list = s['Items']['BinLogFile']        for i in list:            url = i['DownloadLink']            idx = url.split('/')[5].split('?')[0]            filename = "/logs/mysql/mobile/%s/%s" % (date1,idx)            urllib.urlretrieve(url,filename)
binlogmobile('rdsid')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!