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

How do I upload a large SQLite file to Object Storage using OpenStack's Swift (via Python)

我在 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" 错误。我做错了什么?

您需要阅读 Swift DLO/SLO 支持和清单。这是一篇博客 post,可能有助于了解什么是清单以及静态大对象和动态大对象支持之间的区别。

基本上,我推荐以下方法:

  1. Download/install Python-SwiftClient 二进制
  2. 将其上传命令与来自 Bluemix 服务的对象存储凭证结合使用。在上面的清单文章中,它讨论了这种方法 here。请注意 upload 命令、--use-slo 标志的使用以及定义生成的连接段大小的能力。粗略地说,调用将如下所示:

$ 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

祝你好运。