python自动删除minio过期文件
2022/1/7 20:04:20
本文主要是介绍python自动删除minio过期文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#!/usr/local/bin/python3 # -*- coding:utf-8 -*- # ==================================================== # Author: changbo - 541330702@qq.com # Last modified: 2022-01-07 # Filename: miniodeloldfile.py # Description: Del old minio file # http://www.cnblogs.com/changbo # ==================================================== import logging from minio import Minio import time, os import datetime import threading logging.basicConfig( level=logging.INFO, filename='Del.log', filemode='a', format='%(asctime)s %(name)s %(levelname)s--%(message)s' ) nowtime = time.strftime("%Y-%m-%d", time.localtime()) minioClient = Minio( 'x.x.x.x:9000', access_key='xxx', secret_key='xxxx', secure=False ) # 确定要删除的文件 def del_bucket_files(bucketname): try: object = minioClient.list_objects(bucketname, prefix=None, recursive=True) for obj in object: minioFile = 'minio/' + obj.bucket_name + '/' + obj.object_name date1 = time.strptime(str(obj.last_modified).split(' ')[0], "%Y-%m-%d") date2 = time.strptime(nowtime, "%Y-%m-%d") date4 = datetime.datetime(date2[0], date2[1], date2[2]) date3 = datetime.datetime(date1[0], date1[1], date1[2]) if date3 != date4: if int(str(date4-date3).split(' ')[0]) >= 7: print(str(obj.last_modified).split(' ')[0], minioFile) os.system('/root/prometheus-2.26.0.linux-amd64/mc rm ' + minioFile) except Exception as e: print(e) if __name__ == '__main__': thread1 = threading.Thread(target=del_bucket_files, args=("bucketname1",)) thread1.start() thread2 = threading.Thread(target=del_bucket_files, args=("bucketname2",)) thread2.start() thread3 = threading.Thread(target=del_bucket_files, args=("bucketname3",)) thread3.start()
这篇关于python自动删除minio过期文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门