#!/usr/bin/env python#-*- encoding: utf8 -*-import botoimport boto.s3.connectionfrom boto.s3.key import Keyfrom datetime import datetimeimport os# Reference: https://blog.csdn.net/github_25679381/article/details/52943665conn = boto.connect_s3( aws_access_key_id = 'xxxxx', aws_secret_access_key = 'xxxxx', host = 's3.xxxxx', is_secure = False, calling_format = boto.s3.connection.OrdinaryCallingFormat())mytime = datetime.now().strftime('%Y%m%d_%H')bucket = conn.get_bucket('xxxxx') k = Key(bucket)filename = 'xxxxx'+ mytime +'.sql'k.key = filenameos.system("mysqldump -h xxxxx -u xxxxx -pxxxxx --single-transaction xxxxx > "+filename)print 'backup mysql dumpfile finished!'# Download#filename2 = 'xxxxx'#k.get_contents_to_filename(filename2)# Uploadk.set_contents_from_filename(filename)print 'upload to S3 finished!'