from boto.s3.connection import S3Connection
# S3 account
AWS_ACCESS_KEY_ID = ‘엑세스키’
AWS_ACCESS_KEY_SECRET = ‘시크릿키’
# make connection
conn = S3Connection(AWS_ACCESS_KEY_ID, AWS_ACCESS_KEY_SECRET)
# backup target BUCKET
bucket_name = ‘버킷명’
bucket = conn.get_bucket(bucket_name)
# BACKUP DIR and target DIR
backup_dir =’/backup/로컬백업폴더’
target_dir = ‘버킷하위디렉터리명’
# TIME setting to target
import time
utime = time.strftime(‘%Y-%m-%d’)
dest_dir = target_dir+’/’+utime
# search FUNCTION DEF
import os.path, os
def find(inputdir):
return [os.path.join(path, file)
for (path, dirs, files) in os.walk(inputdir)
for file in files]
# Search
listfile=find(backup_dir)
# upload
from boto.s3.key import Key
for list in listfile:
#print(list)
uploadkey = dest_dir+list
print(‘upload files to ‘+bucket_name+’ bucket\n’+’dir = ‘+uploadkey+’\n’)
k = Key(bucket)
k.key = uploadkey
k.set_contents_from_filename(list)
print ‘upload FILES finish’
# END