当前位置: 首页 > news >正文

python3实现gitlab备份文件上传腾讯云COS

gitlab备份文件上传腾讯云COS

  • 脚本说明
    脚本名称:upload.py
    假设gitlab备份文件目录:/opt/gitlab/backups
    gitlab备份文件格式:1706922037_2024_02_06_14.2.1_gitlab_backup.tar1.脚本需和gitlab备份文件同级目录
    2.根据备份文件中的日期判断是否上传,如今天的日期存在于备份文件名列表中,则上传今天备份文件,反之不上传。
    3.如需上传此目录下所有文件,则去掉日期判断逻辑即可upload_cos(file) # ===> 上传单个文件upload_cos(file_list) # ===> 上传目录下所有文件
    
  • 源码如下
    # -*- coding: utf-8 -*-
    # /usr/bin/env python3
    # file_name : upload.py
    # 依赖安装:pip3 install -U cos-python-sdk-v5
    import os
    import sys
    import time
    import datetime
    import logging
    from qcloud_cos import CosConfig
    from qcloud_cos import CosS3Client
    from qcloud_cos.cos_exception import CosClientError, CosServiceErrorlogging.basicConfig(level=logging.INFO, stream=sys.stdout)secret_id = 'SecretId'
    secret_key = 'SecretKey'
    region = 'ap-guangzhou'
    token = Noneconfig = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token)
    client = CosS3Client(config)def upload_cos(file):current = os.getcwd()# 线程上传for i in range(0, 10):try:client.upload_file(Bucket='backup-1145114',Key=f'gitlab/{file}',LocalFilePath=current + '/' + file,)breakexcept CosClientError or CosServiceError as e:print(e)def get_files():# 切换到gitlab备份目录os.chdir('/opt/gitlab/backups')current_dir = os.getcwd()file_list = os.listdir(current_dir)# 脚本文件排除上传if 'upload.py' in file_list:file_list.remove('upload.py')# print(file_list)current_day = datetime.datetime.now().strftime("%Y_%m_%d")for file in file_list:if current_day in file:print('file exist ===>', file)# window下用 \\ ,linux下用 /print(current_dir + "/" + file)upload_cos(file)if __name__ == '__main__':start_time = int(time.time() * 1000)get_files()end_Time = int(time.time() * 1000)allCostTime = end_Time - start_timeprint(f"上传耗时:{allCostTime}ms")
http://www.lryc.cn/news/296395.html

相关文章:

  • 292.Nim游戏
  • Spring和Spring Boot的区别
  • 备战蓝桥杯---动态规划(理论基础)
  • FPGA_ip_pll
  • 【实验3】统计某电商网站买家收藏商品数量
  • 【Qt】Android上运行keeps stopping, Desktop上正常
  • 算法学习打卡day47|单调栈系列题目
  • Maven构建OSGI+HttpServer应用
  • chrome扩展插件常用文件及作用
  • PdfFactory Pro软件下载以及序列号注册码生成器
  • jsp康养小镇管理系统Myeclipse开发mysql数据库web结构java编程计算机网页项目
  • Android 无操作之后定时退出
  • CMS 检测神器:CMSeek 保姆级教程(附链接)
  • oracle 启动命令以及ORA-01033问题处理、删除归档日志
  • 【大模型上下文长度扩展】MedGPT:解决遗忘 + 永久记忆 + 无限上下文
  • 谷歌seo搜索引擎优化有什么思路?
  • 腾讯云与IBM共同打造“高性能计算服务解决方案“
  • 【SparkML实践7】特征选择器FeatureSelector
  • LeetCode983. Minimum Cost For Tickets——动态规划
  • 百卓Smart管理平台 uploadfile.php 文件上传漏洞【CVE-2024-0939】
  • 项目中常用的一些数据库及缓存
  • MoE-LLaVA:具有高效缩放和多模态专业知识的大型视觉语言模型
  • 【Java】ArrayList和LinkedList的区别是什么
  • RabbitMQ-4.MQ的可靠性
  • 编程相关的经典的网站和书籍
  • Java代码实现基数排序算法(附带源码)
  • 基于python+django,我开发了一款药店信息管理系统
  • VSCODE使用ssh远程连接时启动服务器失败问题
  • easyexcle 导出csv
  • Ubuntu22.04 gnome-builder gnome C 应用程序习练笔记(一)