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


    #coding:utf8
    from aliyunsdkcore import client
    from aliyunsdkrds.request.v20140815 import DescribeBackupsRequest
    from aliyunsdkrds.request.v20140815 import DescribeBinlogFilesRequest
    import json
    import urllib
    import datetime
    import os

    def 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')
  • 相关阅读:
    asp.net 2.0 run
    Regular Expression
    assembly
    asp.net loading..
    session
    asp.net performance
    asp.net page order
    interface
    UVA 562 Dividing coins
    UVA 10003 Cutting Sticks
  • 原文地址:https://www.cnblogs.com/liumt-blog/p/11792303.html
Copyright © 2020-2023  润新知