对象存储工具
说明
目前使用过的 对象存储 有: Amazon S3, 阿里云对象存储 OSS 及 ceph,其中 ceph 支持 S3- and Swift-compliant APIs
S3 使用 s3cmd
oss 使用 ossutil
ceph 使用 s3cmd, swift
下面介绍操作对象存储的工具
s3cmd
安装
- 下载,可见 s3cmd
- Mac:
brew install s3cmd
配置
默认配置文件为
~/.s3cfg1
2
3
4
5
6
7[default]
access_key = AK
secret_key = SK
host_base = http://ceph.abc.com
host_bucket = abc
use_https = False
signature_v2 = True
使用
- 查看 bucket 内容:
s3cmd ls s3://abc - 查看 bucket 存储占用:
s3cmd du -H s3://abc - 指定配置文件,并查看内容:
s3cmd -c ~/.s3cfg-hello ls s3://def
ossutil
安装
- 下载,可见 ossutil概述
- Mac:
wget https://gosspublic.alicdn.com/ossutil/1.7.19/ossutil-v1.7.19-mac-arm64.zip。下载特定版本,解压即可 - Linux:
curl https://gosspublic.alicdn.com/ossutil/install.sh | sudo bash,安装完成后,ossutil会安装到/usr/bin/目录下
配置
ossutil config或在~/.ossutilconfig中手动配置
1 | [Credentials] |
使用
- 查看 bucket 内容:
ossutil ls oss://abc
swift
安装
pip install python-swiftclient
使用
查看所有容器:
swift list查看容器 abc 下的对象:
swift list abc查看容器 abc 下的对象 hello.zip 信息:
swift stat abc hello.zip,如果不存在,会返回 404 错误删除容器 abc 下的对象 hello.zip:
swift delete abc hello.zip在 Python 中使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24import os
import logging
import swiftclient
def init_swift(container_name):
auth_url = os.environ['ST_AUTH']
auth_user = os.environ['ST_USER']
auth_key = os.environ['ST_KEY']
conn = swiftclient.Connection(authurl=auth_url, user=auth_user, key=auth_key)
return conn
def get_object_stat(conn, container_name, object_name):
try:
conn.head_object(container_name, object_name)
logging.info('{} exists'.format(object_name))
return True
except Exception as e:
logging.error('{} not exists, err: {}'.format(object_name, e))
return False
def del_object(conn, container_name, object_name):
conn.delete_object(container_name, object_name)
logging.info('{} deleted'.format(object_name))
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 cv-programmer!









