zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    《ASP.NET 本质论》源码下载
    将 Excel 导入到 SharePoint 列表
    使用 jQuery dataTables 3 解析请求参数
    数据库表的转置
    翻译:使用 Entity Framework 4.x 进行代码优先 (CodeFirst) 开发
    转贴:是K2,還是WF(Workflow Foundation)?
    EF CodeFirst 自定义表映射
    CRC原理及其逆向破解方法
    空间坐标转换
    Post Process
  • 原文地址:https://www.cnblogs.com/changbo/p/15776452.html
Copyright © 2011-2022 走看看