-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3sync2oss.py
47 lines (33 loc) · 1.15 KB
/
s3sync2oss.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
author: thomaszdxsn
"""
import asyncio
from tqdm import tqdm
from src.backup.s3 import s3_backup_factory
from src.backup.oss import oss_backup_factory
s3_bakcup = s3_backup_factory()
oss_backup = oss_backup_factory()
async def iterate_bucket_items(bucket):
async with s3_bakcup.create_client() as client:
pagiantor = client.get_paginator('list_objects_v2')
page_iterator = pagiantor.paginate(Bucket=bucket)
async for page in page_iterator:
for item in tqdm(page['Contents']):
yield item
async def copy_obj(key):
# 判断oss是否存在key
if await oss_backup.exists(key):
print('exists')
return
async with s3_bakcup.create_client() as client:
response = await client.get_object(Bucket='dquant1', Key=key)
async with response['Body'] as stream:
body = await stream.read()
await oss_backup.upload(key, body)
print(f"{key} downloaded!!!")
async def main():
keys = []
async for item in iterate_bucket_items('dquant1'):
key = item['Key']
await copy_obj(key)
asyncio.get_event_loop().run_until_complete(main())