美文网首页工作生活
[GIT] 恢复断电导致的gitlab的repository损坏

[GIT] 恢复断电导致的gitlab的repository损坏

作者: w_w_wei | 来源:发表于2019-07-21 08:30 被阅读0次

    背景前提

    自建gitlab,断电后, web端点击项目, 直接显示404页面。



    查看项目所属组,发现存在一个为合并的分支


    bash无法拉取代码

    $ git pull
    error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500 Internal Server Error
    fatal: The remote end hung up unexpectedly
    

    管理员登录web端, 在AdminArea Projects 中还能够看到项目基本详情


    点击按钮, 检测项目,检测失败,查看repocheck.log
     # Logfile created on 2019-07-02 09:42:56 +0000 by logger.rb/61378
    
        E, [2019-07-02T09:42:56.440675 #516] ERROR -- : Could not fsck repository: error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/1d/39daaec870a710014fd534ca319273ce60c482 is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/1d/39daaec870a710014fd534ca319273ce60c482: No such file or directory
    
        error: 1d39daaec870a710014fd534ca319273ce60c482: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/1d/39daaec870a710014fd534ca319273ce60c482
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/35/649a49ce62cb68a2f4f46833611a8306e4b855 is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/35/649a49ce62cb68a2f4f46833611a8306e4b855: No such file or directory
    
        error: 35649a49ce62cb68a2f4f46833611a8306e4b855: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/35/649a49ce62cb68a2f4f46833611a8306e4b855
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/53/1383b717745c519f6106b86adffd758cebd6cc is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/53/1383b717745c519f6106b86adffd758cebd6cc: No such file or directory
    
        error: 531383b717745c519f6106b86adffd758cebd6cc: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/53/1383b717745c519f6106b86adffd758cebd6cc
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/5b/e1a9324912e90e9e36cd6c867c1e7d0ed0c27c is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/5b/e1a9324912e90e9e36cd6c867c1e7d0ed0c27c: No such file or directory
    
        error: 5be1a9324912e90e9e36cd6c867c1e7d0ed0c27c: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/5b/e1a9324912e90e9e36cd6c867c1e7d0ed0c27c
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/70/47c23d5ca7dd11dad54445e7e5d95510eafbc4 is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/70/47c23d5ca7dd11dad54445e7e5d95510eafbc4: No such file or directory
    
        error: 7047c23d5ca7dd11dad54445e7e5d95510eafbc4: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/70/47c23d5ca7dd11dad54445e7e5d95510eafbc4
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/8a/61840e15e0ebe90d50694587497dec06215a93 is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/8a/61840e15e0ebe90d50694587497dec06215a93: No such file or directory
    
        error: 8a61840e15e0ebe90d50694587497dec06215a93: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/8a/61840e15e0ebe90d50694587497dec06215a93
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/93/16329de2806543fd3a79f2d5fe9776a0216fd4 is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/93/16329de2806543fd3a79f2d5fe9776a0216fd4: No such file or directory
    
        error: 9316329de2806543fd3a79f2d5fe9776a0216fd4: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/93/16329de2806543fd3a79f2d5fe9776a0216fd4
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/a1/eabca346796050e6256ebd45791770f1a8c9c7 is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/a1/eabca346796050e6256ebd45791770f1a8c9c7: No such file or directory
    
        error: a1eabca346796050e6256ebd45791770f1a8c9c7: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/a1/eabca346796050e6256ebd45791770f1a8c9c7
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/a9/702dc1b2d93269c928a9417e83df26f2bc6f17 is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/a9/702dc1b2d93269c928a9417e83df26f2bc6f17: No such file or directory
    
        error: a9702dc1b2d93269c928a9417e83df26f2bc6f17: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/a9/702dc1b2d93269c928a9417e83df26f2bc6f17
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/cc/aa3d86df8f6dad83af2904dd17e1276aa5087b is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/cc/aa3d86df8f6dad83af2904dd17e1276aa5087b: No such file or directory
    
        error: ccaa3d86df8f6dad83af2904dd17e1276aa5087b: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/cc/aa3d86df8f6dad83af2904dd17e1276aa5087b
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/d0/34c8674f5449b1ea9e215a758d9adb0962d8b9 is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/d0/34c8674f5449b1ea9e215a758d9adb0962d8b9: No such file or directory
    
        error: d034c8674f5449b1ea9e215a758d9adb0962d8b9: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/d0/34c8674f5449b1ea9e215a758d9adb0962d8b9
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/e6/6cb1a088127cf96fa3054e99fe5ec45a9e6db5 is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/e6/6cb1a088127cf96fa3054e99fe5ec45a9e6db5: No such file or directory
    
        error: e66cb1a088127cf96fa3054e99fe5ec45a9e6db5: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/e6/6cb1a088127cf96fa3054e99fe5ec45a9e6db5
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/f0/49a30ab2203d6fb1e153f2557a13e5f2fc8857 is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/f0/49a30ab2203d6fb1e153f2557a13e5f2fc8857: No such file or directory
    
        error: f049a30ab2203d6fb1e153f2557a13e5f2fc8857: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/f0/49a30ab2203d6fb1e153f2557a13e5f2fc8857
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/fd/e965b652abe5b4cea5456a3f512c8746e3433f is empty
    
        error: unable to mmap /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/fd/e965b652abe5b4cea5456a3f512c8746e3433f: No such file or directory
    
        error: fde965b652abe5b4cea5456a3f512c8746e3433f: object corrupt or missing: /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/fd/e965b652abe5b4cea5456a3f512c8746e3433f
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/a9/702dc1b2d93269c928a9417e83df26f2bc6f17 is empty
    
        error: object file /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/a9/702dc1b2d93269c928a9417e83df26f2bc6f17 is empty
    
        fatal: loose object a9702dc1b2d93269c928a9417e83df26f2bc6f17 (stored in /var/opt/gitlab/git-data/repositories/dev/android_talk.git/objects/a9/702dc1b2d93269c928a9417e83df26f2bc6f17) is corrupt
    
    

    处理

    进入 repository 目录 用 git fsck命令检测,错误很多。

    root@gitlab:/var/opt/gitlab/git-data/repositories/dev/android_talk.git# git fsck                                                                              error: object file ./objects/1d/39daaec870a710014fd534ca319273ce60c482 is empty
    error: unable to mmap ./objects/1d/39daaec870a710014fd534ca319273ce60c482: No su                                                                              ch file or directory
    error: 1d39daaec870a710014fd534ca319273ce60c482: object corrupt or missing: ./ob                                                                              jects/1d/39daaec870a710014fd534ca319273ce60c482
    error: object file ./objects/35/649a49ce62cb68a2f4f46833611a8306e4b855 is empty
    error: unable to mmap ./objects/35/649a49ce62cb68a2f4f46833611a8306e4b855: No su                                                                              ch file or directory
    error: 35649a49ce62cb68a2f4f46833611a8306e4b855: object corrupt or missing: ./ob                                                                              jects/35/649a49ce62cb68a2f4f46833611a8306e4b855
    error: object file ./objects/53/1383b717745c519f6106b86adffd758cebd6cc is empty
    error: unable to mmap ./objects/53/1383b717745c519f6106b86adffd758cebd6cc: No su                                                                              ch file or directory
    error: 531383b717745c519f6106b86adffd758cebd6cc: object corrupt or missing: ./ob                                                                              jects/53/1383b717745c519f6106b86adffd758cebd6cc
    error: object file ./objects/5b/e1a9324912e90e9e36cd6c867c1e7d0ed0c27c is empty
    error: unable to mmap ./objects/5b/e1a9324912e90e9e36cd6c867c1e7d0ed0c27c: No su                                                                              ch file or directory
    error: 5be1a9324912e90e9e36cd6c867c1e7d0ed0c27c: object corrupt or missing: ./ob                                                                              jects/5b/e1a9324912e90e9e36cd6c867c1e7d0ed0c27c
    error: object file ./objects/70/47c23d5ca7dd11dad54445e7e5d95510eafbc4 is empty
    error: unable to mmap ./objects/70/47c23d5ca7dd11dad54445e7e5d95510eafbc4: No su                                                                              ch file or directory
    error: 7047c23d5ca7dd11dad54445e7e5d95510eafbc4: object corrupt or missing: ./ob                                                                              jects/70/47c23d5ca7dd11dad54445e7e5d95510eafbc4
    error: object file ./objects/8a/61840e15e0ebe90d50694587497dec06215a93 is empty
    error: unable to mmap ./objects/8a/61840e15e0ebe90d50694587497dec06215a93: No su                                                                              ch file or directory
    

    删除为0的文件, 再次检测

    root@gitlab:/var/opt/gitlab/git-data/repositories/dev/android_talk.git# find . -                                                                              size 0 -delete
    root@gitlab:/var/opt/gitlab/git-data/repositories/dev/android_talk.git# git fsck                                                                              Checking object directories: 100% (256/256), done.
    Checking objects: 100% (4544/4544), done.
    error: HEAD: invalid sha1 pointer a9702dc1b2d93269c928a9417e83df26f2bc6f17
    error: refs/heads/master: invalid sha1 pointer a9702dc1b2d93269c928a9417e83df26f                                                                              2bc6f17
    dangling blob 6661c1d473296dcf7ff846b25492d874215ddbe1
    

    发现问题变少但是还没有解决, 界面上检测,得到同样的结果


    root@gitlab:/var/opt/gitlab/git-data/repositories/dev/android_talk.git# git log
    fatal: bad object HEAD
    root@gitlab:/var/opt/gitlab/git-data/repositories/dev/android_talk.git# git update-ref HEAD ref:master
    fatal: ref:master: not a valid SHA1
    
    root@gitlab:/var/opt/gitlab/git-data/repositories/dev/android_talk.git# git reflog
    fatal: bad object HEAD
    

    找到最后一次代码合并


    发现 a9702dc1b2d93269c928a9417e83df26f2bc6f17 ,git update-ref更新

    root@gitlab:/var/opt/gitlab/git-data/repositories/dev/android_talk.git# git update-ref HEAD a9702dc1b2d93269c928a9417e83df26f2bc6f17
    root@gitlab:/var/opt/gitlab/git-data/repositories/dev/android_talk.git# git fsck --full
    Checking object directories: 100% (256/256), done.
    Checking objects: 100% (4544/4544), done.
    error: HEAD: invalid sha1 pointer a9702dc1b2d93269c928a9417e83df26f2bc6f17
    error: refs/heads/master: invalid sha1 pointer a9702dc1b2d93269c928a9417e83df26f2bc6f17
    dangling blob 6661c1d473296dcf7ff846b25492d874215ddbe1
    

    发现还是一样 invalid sha1 pointer
    找到最后一次合并的commit_id 63ff9cf659d5c2404a3b2ecc53de6d9dd31296f0

    root@gitlab:/var/opt/gitlab/git-data/repositories/dev/android_talk.git# git update-ref HEAD 63ff9cf659d5c2404a3b2ecc53de6d9dd31296f0
    root@gitlab:/var/opt/gitlab/git-data/repositories/dev/android_talk.git# git fsck --full
    Checking object directories: 100% (256/256), done.
    Checking objects: 100% (4544/4544), done.
    dangling blob 6661c1d473296dcf7ff846b25492d874215ddbe1
    

    再次打开项目



    已经不是404页面。 页面已经到了修改的最后合并的情况。

    参考

    http://blog.jason.tools/2019/01/gitlab-repository-404.html
    https://vincenttam.github.io/blog/2016/08/17/restore-corrupt-git-repository/
    https://ask.helplib.com/git/post_160790

    相关文章

      网友评论

        本文标题:[GIT] 恢复断电导致的gitlab的repository损坏

        本文链接:https://www.haomeiwen.com/subject/xlufhctx.html