• git_backup.py gitlab项目备份


    #!/usr/bin/env python
    # coding=utf-8
    # gitlab源码备份
    
    import os
    import datetime
    import requests
    
    class GitlabBackup:
        def backup_projects(self):
            url = 'http://xxx.xxx.xxx.xxx/api/v3/projects/all?page=1&per_page=1000'
            headers = {'PRIVATE-TOKEN': 'xxxxxx'}
            result = requests.get(url, headers=headers, verify=False)
            json_obj = result.json()
            path = datetime.datetime.now().strftime('%Y%m%d-git-src')
            os.system("rm -rf " + path)
            os.system("mkdir " + path)
            for proj in json_obj:
                self.backup(proj, path)
            # clear data 1 month ago
            del_date = datetime.datetime.now() + datetime.timedelta(days=-32)
            del_path = del_date.strftime("%Y%m*")
            os.system("rm -rf " + del_path)
    
        def backup(self, proj, path):
            url = proj['http_url_to_repo']
            dir = path + '/' + proj['path_with_namespace']
            branch = proj['default_branch']
            if branch is not None:
                print 'starting backup ------>' + dir + ',' + branch
                if os.path.exists(dir):
                    os.system("rm -rf " + dir)
    
                os.system("git clone -b " + branch + " " + url.replace("http://", "http://xxx:xxx@") + " " + dir)
    
    
    
    if __name__ == '__main__':
        gitlab = GitlabBackup()
        gitlab.backup_projects()
  • 相关阅读:
    Windows系统下静态库和动态库的生成方法
    c语言 9-9
    c语言中统计字符串中数字字符出现的次数
    c语言 9-8
    c语言 9-7
    c语言中使用putchar显示字符串
    c语言 9-6
    c语言 9-5
    c语言 9-4
    c语言中输出字符串的长度
  • 原文地址:https://www.cnblogs.com/zhaohz/p/12117156.html
Copyright © 2020-2023  润新知