如何使用OpenStack的Swift(通过Python)将大型SQLite文件上传到对象存储

时间:2016-05-30 06:33:20

标签: python ibm-cloud openstack openstack-swift

我在IBM的Bluemix上有一个Object Storage实例,我正在尝试上传一个~32GB的SQLite文件。这是我的Python代码,它使用OpenStack Swift API(删除了凭据):

import swiftclient
conn = swiftclient.Connection(key="pw",authurl="url",auth_version='3',os_options={"project_id": "project_id","user_id": "user_id","region_name": "region"})
container_name = 'containerName'
file_name = 'file.sqlite'
with open(file_name, 'rb') as sqlite_file:
    conn.put_object(container_name,file_name,sqlite_file)

我用一个小的.html文件测试了这段代码,上传没有问题。当我将文件更改为SQLite文件时,它运行的是> 5个小时,最终给出了“requests.exceptions.ConnectionError:[Errno 32] Broken pipe”错误。我做错了什么?

1 个答案:

答案 0 :(得分:1)

您需要阅读有关Swift DLO / SLO支持和清单的信息。这里有一个博客post,它可能有助于了解哪些清单以及静态大对象和动态大对象支持之间的差异。

基本上,我建议采用以下方法:

  1. 下载/安装Python-SwiftClient二进制文件
  2. 将其upload命令与Bluemix服务中的对象存储凭据结合使用。在上面的清单文章中,它讨论了这种方法here。记下上传命令,使用 - use-slo 标志,以及定义生成的连接段大小的功能。粗略地说,调用将如下所示:
  3. $ swift --os-auth-url=https://identity.open.softlayer.com/v3 --os-user- id=some_hex_value --os-password="weird_characters" --os-project-id=another_hex_value --os-region-name=dallas -V 3 upload my_object_storage_container_name -S int_seg_size_in_bytes my_local_large_file_with_some_extension --use-slo

    my_local_large_file_with_some_extension segment 3
    my_local_large_file_with_some_extension segment 1
    my_local_large_file_with_some_extension segment 2
    my_local_large_file_with_some_extension segment 0
    my_local_large_file_with_some_extension/1443450560.000000/160872806/52428800/00000002
    my_local_large_file_with_some_extension/1443450560.000000/160872806/52428800/00000003
    my_local_large_file_with_some_extension/1443450560.000000/160872806/52428800/00000001
    my_local_large_file_with_some_extension/1443450560.000000/160872806/52428800/00000000
    my_local_large_file_with_some_extension
    
    祝你好运。