定期备份和清理gitlab文件
2024-08-26 22:54:03
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019-12-05 14:39
# @Author : Anthony
# @Email : ianghont7@163.com
# @File : check_gitlab.py # import requests
# import re
# import time
#
# url = "http://gitlab.test.cn/api/v3/projects?private_token=xxxxx"
#
# response = requests.get(url)
# print(response.json())
# import os
import time
import datetime
import threading
import subprocess # 注意点,千万要注意不要和内置方法重名啊!!!! # 文件所在路径
source_path = "/home/xxx/xxx/" # 当前时间
now_time = datetime.datetime.now() # 获取全部文件名称
source_path_lists = os.listdir(source_path) # 清理过期文件,只保留7天内
def remove_dated_files():
# 选择要提前的天数
change_time = now_time + datetime.timedelta(days=-2)
# 格式化处理时间戳
change_time_format = change_time.strftime('%Y%m%d')
for line in source_path_lists:
file_ctime = int(line.split('_')[0].strip())
file_local_time = time.localtime(file_ctime)
# 文件名中的时间戳
file_local_time_end = time.strftime("%Y%m%d", file_local_time)
# 清理2天前的过期文件
if file_local_time_end <= change_time_format:
all_file_path = source_path + line
# 清理过期文件
os.remove(all_file_path)
print('2天前过期文件 %s 清理完成,该文件创建时间:%s' % (all_file_path, file_local_time_end)) def get_gitlab_backup_fils():
for line in source_path_lists:
all_file_path = source_path + line
print(all_file_path)
args = "scp -P xxxx %s root@192.168.xx.xx:/home/data/gitlabbackup"%all_file_path
shell_runnings = subprocess.Popen(args,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,)
out, err = shell_runnings.communicate()
for line in out.splitlines():
print('开始传输:%s'%line) if __name__ == "__main__":
threads_lists = [threading.Thread(target=remove_dated_files),
threading.Thread(target=get_gitlab_backup_fils)]
for i in threads_lists:
i.start()
最新文章
- BluetoothChat用于蓝牙串口通信的修改方法
- [8.2] Robot in a Grid
- jquery 使用需要注意
- hibernate 问题集
- 20145222黄亚奇《Java程序设计》实验四实验报告
- 理解jar
- 鼠标HOVER时区块动画旋转变色的CSS3样式掩码
- 如何在Blog中使用feedburner管理RSS订阅
- 使用sublime text3 连接sftp/ftp(远程服务器)
- ESPlatform 支持的三种群集模型 —— ESFramework通信框架 4.0 进阶(09)
- 使用PHP实现文件上传和多文件上传
- Deming管理系列(2)——怎样开发度量能力
- Spider_Man_2 の requests模块
- android binder机制详解
- php函数 array_count_values
- InnoDB中锁的模式
- UAC 实现原理及绕过方法
- poj2253 最短路
- gem install没有反应 解决办法
- Animation.wrapMode循环模式
热门文章
- Spring boot MyBatis基本操作
- Python2和Python3共存问题
- ubuntu之路——day11.5 迁移学习
- 关于 array of const
- 修改layui的表单手机、邮箱验证可以为空怎么实现?
- java/spring boot/dubbo/spring cloud/微服务/SOA/分布式经典电子书籍pdf下载
- PHP 输出日志到文件 DEMO
- textEdit
- spark.sql.shuffle.partitions和spark.default.parallelism的区别
- Web Service 和 WCF的比较