Python实现向s3共享存储上传和下载文件


#!/usr/bin/env python
#-*- encoding: utf8 -*-

import boto
import boto.s3.connection
from boto.s3.key import Key
from datetime import datetime
import os
# Reference: https://blog.csdn.net/github_25679381/article/details/52943665

conn = 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 = filename

os.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)


# Upload
k.set_contents_from_filename(filename)

print 'upload to S3 finished!'

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM