加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pullOfMinio.py 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
hhu 提交于 2021-08-06 23:17 . 111
import logging
from minio import Minio
from minio.error import S3Error
import datetime
import configparser
logging.basicConfig(level=logging.INFO)
cnf_file = "myback.ini"
config = configparser.ConfigParser()
config.read(cnf_file)
minio_host = config.get("minio", "minio_host")
access_key = config.get("minio", "access_key")
secret_key = config.get("minio", "secret_key")
project_code = config.get("minio", "project_code")
storage_path = config.get("download", "storage_path")
pull_start_at = config.get("download", "pull_start_at")
pull_end_at = config.get("download", "pull_end_at")
minioClient = Minio(
minio_host,
access_key,
secret_key,
secure=False
)
def bucket_list_files(bucket_name, prefix):
try:
need_pull_files = []
files_list = minioClient.list_objects(bucket_name=bucket_name, prefix=prefix, recursive=True)
for obj in files_list:
if "backupfilelist" in obj.object_name:
need_pull_files.append(obj.object_name)
else:
bak_datetime = datetime.datetime.strptime(obj.object_name.replace("_full.tar.gz", "").replace("_incr.tar.gz", "").replace("mysql/",""), '%Y%m%d%H%M%S')
pull_start_at_time = datetime.datetime.strptime(pull_start_at, '%Y-%m-%d %H:%M:%S')
pull_end_at_time = datetime.datetime.strptime(pull_end_at, '%Y-%m-%d %H:%M:%S')
if bak_datetime >=pull_start_at_time and bak_datetime <=pull_end_at_time:
need_pull_files.append(obj.object_name)
print("符合时间要求的文件名列表:{0}".format(need_pull_files))
return need_pull_files
except S3Error as e:
logging.error("list file failed:", e)
def pullOfMinio():
try:
need_pull_files = bucket_list_files("mysqlbackup",project_code)
for filename in need_pull_files:
minioClient.fget_object("mysqlbackup", filename, "{0}/{1}".format(storage_path,filename))
logging.info("成功拉取文件:{}".format(filename))
except BaseException as err:
logging.error("拉取文件错误:", err)
if __name__ == '__main__':
pullOfMinio()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化