上一篇,写的是如何部署 MinIO,以及通过浏览器管理对象存储。本篇主要讲的是,如何用 Python 使用 MinIO SDKs 来备份目录和数据库。
使用 MinIO 命令行操作# 下载客户端
[[email protected] ~]# wget https://dl.min.io/client/mc/release/linux-amd64/mc
[[email protected] ~]# chmod +x mc
[[email protected] ~]# mv mc /usr/bin
[[email protected] ~]# mc --help
# 连接对象服务器
[[email protected] ~]# mc config host add minio http://docker:9000 access_key secret_key
Added `minio` successfully.
# 列出文件
[[email protected] ~]# mc ls minio
安装 MinIO SDKspip install minio
Python 的基本操作# 初始化 MinIO 对象
from minio import Minio
from minio.error import ResponseError
minioClient = Minio('play.min.io',
access_key='YOUR ACCESS KEY',
secret_key='YOUR SECRET KEY',
secure=True)# 调用make_bucket来创建一个存储桶。
try:
minioClient.make_bucket("maylogs", location="us-east-1")
except BucketAlreadyOwnedByYou as err:
pass
except BucketAlreadyExists as err:
pass
except ResponseError as err:
raise
else:
try:
minioClient.fput_object('maylogs', 'pumaserver_debug.log', '/tmp/pumaserver_debug.log')
except ResponseError as err:
print(err)
Python 自动备份脚本pip安装指南:pip/pip3 install minio#python myminio.py site bucket_name backup_name /backup_path keep_newest_copies
python myminio.py site testbucket mywebsite /backup 5
参考文献