创建python脚本
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkrds.request.v20140815.DescribeBackupsRequest import DescribeBackupsRequest
import sys
import requests
import os
accessKeyId = 'LTAIgiWKGePg'
accessSecret = 'vKJxY3RAf4fXQEvX92xlgFk'
IDC = 'cn-beijing'
RDS_ID = 'rm-2ze4o4585a4'
localpath = 'G:\data_bak\mysql_shell\down_mysql\l'
def download_url(accessKeyId,accessSecret,IDC):
client = AcsClient(accessKeyId,accessSecret,IDC)
request = DescribeBackupsRequest()
request.set_accept_format('json')
request.set_DBInstanceId(RDS_ID)
response = client.do_action_with_exception(request)
dic_tems = eval(response)
url = dic_tems.get('Items').get('Backup')[0].get('BackupDownloadURL')
filename = url.split('?')[0].split('/')[-1]
return url,filename
def down_database(url,filename,localpath):
file_path = localpath + filename
requests.packages.urllib3.disable_warnings()
if os.path.exists(file_path):
temp_size = os.path.getsize(file_path)
else:
temp_size = 0
headers = {'Range': 'bytes=%d-' % temp_size}
r = requests.get(url, stream=True, verify=False, headers=headers)
with open(file_path, "ab") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
temp_size += len(chunk)
f.write(chunk)
f.flush()
if __name__ == "__main__":
url,filename = download_url(accessKeyId,accessSecret,IDC)
down_database(url,filename,localpath)
定时执行python脚本即可