gitlab批量导入导出

2022年7月1日 09:24 by wst

python运维

最近服务到期,不得不把代码库(gitlab11.1.0)迁移走。

顺手部署了个新版的gitlab13.7.3, 由于版本不一致,直接备份导入会报错。

经过查找,python有个库python-gitlab可以干这个事。

思路是:先从旧库导出,然后导入到新库。

代码如下:

#!/usr/bin/env python

"""
FileName: migrate_gitlab
Author: wst
Email: movingheart000@gmail.com
Date: 2022/6/29 20:40:28
Desc: 
"""
import os

import gitlab
import time
import subprocess
import json


def runcmd(command):
    ret = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8",
                         timeout=2000)
    if ret.returncode == 0:
        print("success:", ret)
    else:
        print("error:", ret)


class MigrateGitlab:
    def __init__(self, url, token, aim_url, aim_token):
        self.gl = gitlab.Gitlab(url, token)
        self.aim_gl = gitlab.Gitlab(aim_url, aim_token)
        self.dir_path = "/home/wst/Documents/tmp/"       # 导出文件放置目录

    def download_repository(self):
        """下载仓库"""
        projects = self.gl.projects.list(all=True)
        for p in projects:
            print(f"id:{p.id}, \nname:{p.name}, \ndescription:{p.description}")
            print(f"ssh_url_to_repo:{p.ssh_url_to_repo}")
            export = p.exports.create()

            # Wait for the 'finished' status
            export.refresh()
            while export.export_status != 'finished':
                time.sleep(1)
                export.refresh()

            # Download the repo
            fn = f'{self.dir_path}{p.name}.tar.gz'
            with open(fn, 'wb') as f:
                export.download(streamed=True, action=f.write)

    def upload_repository(self):
        """上传仓库"""
        done_names = list()
        for file in os.listdir(self.dir_path):
            base_name = file.split(".", 1)[0]
            fn = os.path.join(self.dir_path, file)
            print("正在导入:", fn)
            # Import result
            with open(fn, 'rb') as f:
                try:
                    output = self.aim_gl.projects.import_project(
                        f, path=base_name, name=base_name, namespace='wst', overwrite=True
                    )
                    done_names.append(base_name)
                except gitlab.exceptions.GitlabHttpError as e:
                    if "Name has already been taken" in e.error_message:
                        # 若库已存在, 则忽略
                        print(f"{base_name} 已经存在!")
                    else:
                        print("导库出现未知错误!")
                except Exception as e:
                    print("e:", e, type(e), dir(e))
                    print(f"{base_name} 导入异常,请检查原因,或稍后手动导入。")
                finally:
                    json.dump(done_names, open("names.json", "w"))
            print(f"本项目[{base_name}]迁移结束!")

if __name__ == "__main__":
    url_ = "http://7.4.1.2"
    token_ = "eFFutSVYkUS2NF8rLUCx"
    aim_url_ = "https://gitlab.wo.com"
    aim_token_ = "w24PNqszNvepb9oSYzq8"
    imp_obj = MigrateGitlab(url_, token_, aim_url_, aim_token_)
    imp_obj.download_repository()
    imp_obj.upload_repository()

 

版权声明:

本文刊载的所有内容,包括文字、图片以及网页版式设计等均为本人自主创作,访问者可将本文提供的内容或服务用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯本文及作者的合法权利。除此以外,将本文任何内容或服务用于其他用途时,须征得本人的书面许可,并支付报酬。email: movingheart000@gmail.com, wx:wst_ccut


Comments(127) Add Your Comment

Deqdta
atorvastatin 80mg generic <a href="https://lipiws.top/">atorvastatin 20mg usa</a> buy atorvastatin pills for sale
Hjjcgn
ciprofloxacin 500mg usa - <a href="https://metroagyl.top/clindamycin/">trimethoprim usa</a> buy augmentin 625mg online
Nbrxjv
ciprofloxacin tablet - <a href="https://cipropro.top/bactrimos/">order bactrim 480mg generic</a> augmentin 1000mg over the counter
Joclko
oral flagyl 200mg - <a href="https://metroagyl.top/cefaclor/">buy cefaclor paypal</a> purchase azithromycin generic
Efepsu
order ciprofloxacin 500 mg generic - <a href="https://septrim.top/erythromycin/">purchase erythromycin</a> how to get erythromycin without a prescription
Lxugap
valacyclovir cost - <a href="https://gnantiviralp.com/zovirax/">buy zovirax 800mg pills</a> order acyclovir 400mg online cheap
Ksdipw
ivermectin 3mg over counter - <a href="https://keflexin.top/sumycin/">order sumycin sale</a> buy sumycin
Wtadvj
flagyl 400mg over the counter - <a href="https://metroagyl.top/clindamycin/">cleocin 300mg uk</a> azithromycin over the counter
Xoxuqn
buy generic ampicillin online <a href="https://ampiacil.top/">buy ampicillin pill</a> purchase amoxil without prescription
Zcmuuw
order lasix 100mg pills - <a href="https://antipathogenc.com/medex/">order medex generic</a> purchase capoten pill
Cjjnnj
buy retrovir 300mg for sale - <a href="https://canadiangnp.com/epivir/">lamivudine 100 mg generic</a> brand zyloprim 300mg
Zbmfwy
glycomet usa - <a href="https://gnantiacidity.com/">metformin 1000mg for sale</a> lincomycin tablet
Bxkvye
cost clozaril - <a href="https://genonlinep.com/accupril/">purchase accupril online</a> famotidine 40mg drug
Hysiyo
brand quetiapine - <a href="https://gnkantdepres.com/">quetiapine over the counter</a> eskalith us
Fhadmq
order atarax for sale - <a href="https://antdepls.com/pamelor/">order pamelor for sale</a> endep 10mg cost
Itqcbj
anafranil 25mg for sale - <a href="https://antdeponline.com/remeron/">mirtazapine 15mg cost</a> buy doxepin no prescription
Ultwsf
amoxicillin pills - <a href="https://atbioxotc.com/ceftin/">purchase axetil generic</a> order cipro pill
Kjcaoq
buy augmentin 625mg pill - <a href="https://atbioinfo.com/ampicillin/">buy ampicillin cheap</a> cipro 1000mg price
Yxliyw
buy cheap generic clindamycin - <a href="https://cadbiot.com/cefpodoxime/">cefpodoxime over the counter</a> chloromycetin pills
Hwqypt
how to get azithromycin without a prescription - <a href="https://gncatbp.com/btetracycline/">where to buy sumycin without a prescription</a> buy ciprofloxacin pills
Lfnfdw
order albuterol online - <a href="https://antxallergic.com/xsseroflo/">purchase seroflo online cheap</a> order theophylline generic
Ryclht
purchase stromectol online - <a href="https://antibpl.com/aqdapsone/">buy aczone pills</a> order cefaclor 500mg without prescription
Yvbeyp
clarinex for sale online - <a href="https://rxtallerg.com/">desloratadine order</a> ventolin 4mg oral
Niartu
methylprednisolone 8 mg pills - <a href="https://ntallegpl.com/">medrol 16 mg online</a> azelastine buy online
Bicclu
order glyburide without prescription - <a href="https://prodeprpl.com/pioglitazone30/">actos over the counter</a> dapagliflozin 10mg pill
Jlynup
buy generic repaglinide 2mg - <a href="https://depressinfo.com/jardiance25/">buy empagliflozin generic</a> order generic jardiance 25mg
Tlcgid
glucophage where to buy - <a href="https://arxdepress.com/acarbose50/">buy acarbose</a> precose 25mg ca
Inicxx
how to get lamisil without a prescription - <a href="https://treatfungusx.com/fulvicin250mg/">fulvicin online</a> grifulvin v us
Mrtqro
rybelsus pills - <a href="https://infodeppl.com/ddavpspray/">desmopressin spray</a> DDAVP medication
Pqtrvs
order nizoral 200mg generic - <a href="https://antifungusrp.com/">order nizoral online cheap</a> sporanox 100mg tablet
Mmgema
purchase lanoxin without prescription - <a href="https://blpressureok.com/avalidemed/">buy irbesartan 300mg generic</a> brand furosemide 100mg
Sycobs
famciclovir 500mg usa - <a href="https://amvinherpes.com/">how to get famciclovir without a prescription</a> valaciclovir 500mg brand
Czhuzy
hydrochlorothiazide cost - <a href="https://norvapril.com/amlodipine/">norvasc pill</a> bisoprolol medication
Hkzowz
lopressor 50mg uk - <a href="https://bloodpresspl.com/hyzaar/">cozaar 50mg over the counter</a> adalat buy online
Azqouh
nitroglycerin order online - <a href="https://nitroproxl.com/indapamide/">order generic indapamide 2.5mg</a> generic diovan 80mg
Pokzda
crestor pills vanish - <a href="https://antcholesterol.com/">rosuvastatin online quiver</a> caduet pills trifle
Mnorgu
simvastatin ink - <a href="https://canescholest.com/fenofibrate/">fenofibrate decent</a> atorvastatin lover
Yvcawh
viagra professional online task - <a href="https://edsildps.com/cialisprofessional/">cialis professional bitter</a> levitra oral jelly online chain
Pmrhki
priligy history - <a href="https://promedprili.com/aurogra/">aurogra excuse</a> cialis with dapoxetine drug
Atfioe
cenforce people - <a href="https://xcenforcem.com/tadaciptadalafil/">tadacip severe</a> brand viagra pills native
Cbasms
brand cialis float - <a href="https://probrandtad.com/penisole/">penisole hopeless</a> penisole fireplace
Qspifu
cialis soft tabs issue - <a href="https://supervalip.com/">cialis soft tabs pills extent</a> viagra oral jelly online camp
Gqauoh
brand cialis triumph - <a href="https://probrandtad.com/forzestpills/">forzest group</a> penisole hire
Zyhntd
cialis soft tabs pills couple - <a href="https://supervalip.com/cavertapills/">caverta online dark</a> viagra oral jelly online stir
Uaxbju
cenforce reluctant - <a href="https://xcenforcem.com/tadaciptadalafil/">tadacip individual</a> brand viagra online london
Twiybe
dapoxetine propose - <a href="https://promedprili.com/fildena/">fildena dark</a> cialis with dapoxetine defeat
Owlwwk
acne treatment exhaust - <a href="https://placnemedx.com/">acne treatment please</a> acne medication watson
Aicumk
inhalers for asthma professor - <a href="https://bsasthmaps.com/">asthma treatment din</a> asthma medication president
Wawoit
uti antibiotics shrug - <a href="https://amenahealthp.com/">uti medication neat</a> uti antibiotics fire
Vdnxws
pills for treat prostatitis pool - <a href="https://xprosttreat.com/">prostatitis treatment bond</a> prostatitis treatment cast
Llncry
valacyclovir license - <a href="https://gnantiviralp.com/">valacyclovir terrorist</a> valacyclovir greet
Pqgsiy
loratadine nurse - <a href="https://clatadine.top/">claritin clean</a> loratadine wake
Etdvss
claritin pills social - <a href="https://clatadine.top/">claritin pills sleeve</a> loratadine wise
Ulqnal
priligy sorry - <a href="https://prilixgn.top/">priligy mine</a> priligy interval
Dvnvnz
promethazine heat - <a href="https://prohnrg.com/">promethazine goblin</a> promethazine awful
Hxuhba
ascorbic acid envelope - <a href="https://ascxacid.com/">ascorbic acid accord</a> ascorbic acid proceed
Mbcbdr
florinef pills supply - <a href="https://gastroplusp.com/">fludrocortisone shutter</a> lansoprazole advice
Ihuqlx
clarithromycin pills damage - <a href="https://gastropls.com/">clarithromycin joe</a> cytotec granny
Kekfpy
order dulcolax 5 mg pills - <a href="https://gastroinfop.com/">brand dulcolax 5 mg</a> brand liv52
Usggzc
cost aciphex 20mg - <a href="https://gastrointesl.com/reglanmetoclop/">buy reglan 20mg sale</a> motilium over the counter
Afcvnz
how to buy bactrim - <a href="https://tobmycin.com/">tobramycin online order</a> buy tobrex without prescription
Uylimv
hydroquinone where to buy - <a href="https://cerazestrel.com/">purchase desogestrel online cheap</a> duphaston online
Ctewlb
forxiga online buy - <a href="https://precarbos.com/">cost acarbose</a> order acarbose 50mg sale
Neudwy
purchase fulvicin for sale - <a href="https://fulviseoful.com/">fulvicin 250 mg brand</a> lopid 300mg canada
Dxgofs
buy vasotec 5mg generic - <a href="https://doxapisin.com/">doxazosin price</a> xalatan over the counter
Stnkfi
buy dimenhydrinate 50mg online cheap - <a href="https://actodronate.com/">purchase actonel pills</a> risedronate 35 mg uk
Vjnoww
piroxicam 20 mg over the counter - <a href="https://rivastilons.com/">rivastigmine pills</a> purchase rivastigmine for sale
Rwwjit
monograph 600 mg without prescription - <a href="https://cilosetal.com/">cilostazol pills</a> cheap pletal 100mg
Wwvyda
buy hydroxyurea for sale - <a href="https://hydroydrinfo.com/indinavir/">buy indinavir without prescription</a> robaxin order online
Spyysc
order piracetam sale - <a href="https://nootquin.com/praziquantel/">order praziquantel 600mg pill</a> cost sinemet 20mg
Jjrewg
disopyramide phosphate pill - <a href="https://anorpica.com/">cheap disopyramide phosphate generic</a> chlorpromazine 100mg uk
Zrmxnq
generic divalproex 250mg - <a href="https://adepamox.com/aspirindipyridamole/">brand aggrenox</a> topamax online buy
Cmwxwe
buy cyclophosphamide pills for sale - <a href="https://cycloxalp.com/dimenhydrinate/">buy generic dramamine over the counter</a> order trimetazidine
Oqqgpr
where can i buy aldactone - <a href="https://aldantinep.com/">generic aldactone 100mg</a> where can i buy revia
Pnjtix
buy cyclobenzaprine generic - <a href="https://abflequine.com/prasugrel/">prasugrel 10 mg drug</a> buy generic enalapril over the counter
Wcguzv
purchase ondansetron online cheap - <a href="https://azofarininfo.com/ropinirole/">ropinirole 1mg for sale</a> requip 2mg without prescription
Itbgst
oral ascorbic acid 500mg - <a href="https://mdacidinfo.com/prochlorperazine/">prochlorperazine where to buy</a> compro canada
Htjmhg
purchase cheap durex gel - <a href="https://xalaplinfo.com/durexcondoms/">buy durex condoms</a> xalatan brand
Rwadtx
how to buy arava - <a href="https://infohealthybones.com/alfacalcidol/">cheap alfacip for sale</a> where can i buy cartidin
Phzyls
minoxidil usa - <a href="https://hairlossmedinfo.com/finasteridehl/">buy finasteride generic</a> buy generic finasteride
Owmalg
atenolol 50mg ca - <a href="https://heartmedinfox.com/sotalol/">order betapace 40mg</a> order carvedilol 6.25mg generic
Vebrds
verapamil canada - <a href="https://infoheartdisea.com/cardizem/">buy diltiazem pill</a> cheap tenoretic generic
Svdmep
buy generic atorlip online - <a href="https://infoxheartmed.com/">buy generic atorlip online</a> nebivolol 20mg canada
Sbngac
lasuna over the counter - <a href="https://infoherbalmz.com/diarex/">buy diarex cheap</a> brand himcolin
Bbgakr
buy gasex pills for sale - <a href="https://herbalinfomez.com/">gasex cost</a> diabecon order
Gigztm
buy generic speman over the counter - <a href="https://spmensht.com/">buy speman tablets</a> fincar tablets
Fhjozu
buy norfloxacin pills - <a href="https://gmenshth.com/flutamide/">eulexin usa</a> confido order online
Nhembs
hytrin 1mg pill - <a href="https://hymenmax.com/dutasteride/">purchase dutasteride pill</a> order priligy 90mg sale
Jeyjdi
buy lactulose online cheap - <a href="https://duphalinfo.com/">lactulose for sale</a> purchase betahistine pills
Ikqsio
cheap trileptal 600mg - <a href="https://trileoxine.com/levothyroxine/">generic synthroid 150mcg</a> buy synthroid 75mcg online
Ysroxe
buy imusporin paypal - <a href="https://asimusxate.com/methotrexate/">methotrexate 2.5mg without prescription</a> buy gloperba generic
Xtoxaz
deflazacort brand - <a href="https://lazacort.com/brimonidine/">cheap alphagan</a> brimonidine online order
Rdgwly
besivance over the counter - <a href="https://besifxcist.com/carbocysteine/">buy carbocisteine pills for sale</a> buy sildamax tablets
Bsmyki
purchase neurontin generic - <a href="https://aneutrin.com/">purchase gabapentin pill</a> order sulfasalazine 500 mg online cheap
Fomvxx
purchase benemid generic - <a href="https://bendoltol.com/monograph/">order etodolac 600mg</a> carbamazepine usa
Mdevpr
how to get colospa without a prescription - <a href="https://coloxia.com/etoricoxib/">order generic etoricoxib</a> pletal 100mg pills
Uuywap
celecoxib cost - <a href="https://celespas.com/indomethacin/">order indomethacin 50mg without prescription</a> indomethacin over the counter
Jzxrkv
voltaren 100mg usa - <a href="https://dicloltarin.com/">buy voltaren 50mg sale</a> cost aspirin 75 mg
Zbanxp
order rumalaya pill - <a href="https://rumaxtol.com/">rumalaya online</a> order elavil 10mg online cheap
Nlnucr
purchase pyridostigmine generic - <a href="https://mestonsx.com/azathioprine/">imuran medication</a> azathioprine 50mg oral
Jdzunb
order voveran pills - <a href="https://vovetosa.com/animodipine/">buy nimotop without a prescription</a> buy nimotop generic
Bzuscf
baclofen 10mg us - <a href="https://baclion.com/">buy baclofen 10mg generic</a> oral piroxicam 20 mg
Rxbpzw
buy generic mobic over the counter - <a href="https://meloxiptan.com/rtrizatriptan/">ketorolac cost</a> buy ketorolac no prescription
Mynhih
cyproheptadine 4mg generic - <a href="https://periheptadn.com/aszanaflex/">buy generic zanaflex</a> cost zanaflex
Fonlwp
buy trihexyphenidyl pills for sale - <a href="https://voltapll.com/diclofenacgel/">voltaren gel where to buy</a> buy diclofenac gel
Lymtdb
cefdinir for sale - <a href="https://omnixcin.com/">cefdinir online</a> cleocin buy online
Xkejrz
buy isotretinoin 20mg pills - <a href="https://aisotane.com/asdeltasone/">deltasone 20mg for sale</a> order deltasone 10mg generic
Txexkf
prednisone 40mg us - <a href="https://apreplson.com/">deltasone 40mg pills</a> cheap elimite
Jsetqv
acticin price - <a href="https://actizacs.com/">purchase permethrin cream</a> tretinoin cream us
Owgmrn
flagyl 200mg without prescription - <a href="https://ametronles.com/">metronidazole 200mg cheap</a> purchase cenforce online
Vndqwh
order betamethasone 20gm generic - <a href="https://betnoson.com/benoquincre/">order benoquin without prescription</a> benoquin medication
Pxvozl
order augmentin 375mg - <a href="https://baugipro.com/">clavulanate pill</a> buy generic synthroid 75mcg
Sshwnw
buy cleocin cheap - <a href="https://indometnp.com/">indocin 50mg brand</a> indocin 50mg over the counter
Bogpri
cozaar 50mg sale - <a href="https://cozartan.com/">buy hyzaar cheap</a> purchase keflex online
Kcmfei
order generic crotamiton - <a href="https://aeuracream.com/caczone/">aczone online buy</a> brand aczone
Pggxig
buy bupropion generic - <a href="https://bupropsl.com/">order bupropion 150mg for sale</a> purchase shuddha guggulu generic
Uchysa
buy modafinil medication - <a href="https://sleepagil.com/">buy modafinil online cheap</a> meloset cheap
Owuckh
buy prometrium 200mg sale - <a href="https://apromid.com/clomipheneferto/">buy clomiphene pills</a> buy fertomid pill
Iibdyy
buy xeloda for sale - <a href="https://xelocap.com/naproxen/">buy cheap generic naprosyn</a> buy danocrine 100mg online
Aqcgkh
order generic aygestin - <a href="https://norethgep.com/">buy norethindrone 5 mg without prescription</a> buy yasmin generic
Gktrkt
order alendronate 70mg generic - <a href="https://pilaxmax.com/tamoxifen/">where can i buy tamoxifen</a> order medroxyprogesterone without prescription
Ijjgeg
buy cabergoline 0.5mg - <a href="https://adostilin.com/alesse/">alesse usa</a> buy alesse
Bbkdvm
estrace ca - <a href="https://festrolp.com/ginette-35/">buy ginette 35 generic</a> buy arimidex 1mg online cheap
Lfnhug
シルデナフィル どこで買える - <a href="https://jpedpharm.com/">タダラフィルジェネリック 通販</a> シアリス通販
Vptwoj
プレドニン通販おすすめ - <a href="https://jpaonlinep.com/jamoxicillin/">アモキシル 市販 おすすめ</a> アジスロマイシン 薬局で買える
Higyod
プレドニン 飲み方 - <a href="https://jpanfarap.com/">プレドニン 個人輸入 おすすめ</a> アキュテイン 値段
Oshtkq
eriacta upward - <a href="https://eriagra.com/fforzestf/">forzest universal</a> forzest cellar