华为云OBS数据迁移阿里云OSS

一、使用阿里云提供的迁移工具ossimport

参考:https://help.aliyun.com/document_detail/59922.html?spm=a2c4g.11174283.6.1521.62e37da2i1S2WP

因为ossimport不能直接支持OBS的迁移,所以我们使用http的方式迁移

二、华为云创建操作OBS的子账号,拥有读取OBS的权限

三、pip安装obs的sdk

pip install esdk-obs-python 

四、编写获取OBS所有文件的脚本

from obs import ObsClient


url='https://xxxxxxxxxxx.obs.cn-north-1.myhuaweicloud.com/' #华为云OBS公网访问地址

obsClient = ObsClient(
    access_key_id='xxxxxxxxxx',
    secret_access_key='xxxxxxxxxxxxx',
    server='https://obs.cn-north-1.myhuaweicloud.com'  #地区
)
marker = '1'


def get_all():
    global marker,url
    file = '/usr/local/ossimport/http/http.list'  #保存obs所有文件的文件
    clear_file = open(file, 'w')

    while marker:
        if marker == '1':
            marker = None
        resp = obsClient.listObjects('xxxxxxx',marker=marker) #OBS的名称
        if resp.status < 300:
            index = 1
            with open(file,'a') as f:
                for content in resp.body.contents:
                    http = url+'    '+content.key
                    f.write(http)
                    f.write('\n')
                    index += 1
            marker = resp.body.next_marker
        else:
            print('errorCode:', resp.errorCode)
            print('errorMessage:', resp.errorMessage)

if __name__ == '__main__':
    get_all()

五、创建OSS桶

六、创建子账号并拥有管理OSS桶的权限

七、修改ossimport的配置

八、迁移

猜你喜欢

转载自www.cnblogs.com/zhangb8042/p/12794381.html