Server Restore: Linking bare GitLab repos to where their LFS objects are stored

Hello, I’ve been trying to restore the repositories of a dead GitLab server of mine. After the server’s death I have copies of most of the server’s file system, most importantly the <repositories> and <lfs-objects> folder, and I believe this is enough to restore all of my data!

I have already had success navigating to the hashed repos, giving them a new remote, and pushing to a new server endpoint. However, repos with LFS are missing all of their objects. This is because all LFS objects on the server are stored in the location specified by the gitlab.rb document. In my cause this is the default option, /var/opt/gitlab/gitlab-rails/shared/<lfs-objects>.

Given this, how might I help my repos figure out where their LFS objects are? Thinking about the server side of LFS is a little beyond me, but on a surface level this seems solvable. I’d appreciate any advice, or simply suggestions on where I’d look next to learn about how I might solve this.

For Clarity, here are some detailed steps to replicate my situation:

Replicating the Problem:

  • Install gilab-ce on Ubuntu
    • Take note of the <lfs-objects> folder (/var/opt/gitlab/gitlab-rails/shared/lfs-objects) and the <repositories> folder (/var/opt/gitlab/git-data). Both are empty.
  • Create a local project with git and track an object with LFS
    • git init
    • git lfs install
    • git lfs track .test
    • touch file.test
    • git add .
    • git commit -m “commit lfs obj”
    • git remote add origin <remote-url>
    • git push --all
  • Now note where the repo data ended up
    • The new repo is under <repositories>/@hashed/<hash>/<other-hash>/<long-hash>.git. You can check the config file and “fullpath” will show the project’s name
    • <lfs-objects> will now have a hashed directory with the object in it.
  • Oh no, your server has died! Backup the <repositories> and <lfs-objects> directories to a removable drive :frowning:

The Solution so far

  • Install gitlab-ce on Ubuntu somewhere else
  • cd into one of the backed up repo. <repositories>/<hash>/<other-hash>/<long-hash>.git. This is a bare project repo.
  • git remote set-url origin <new-remote-url>
  • git push origin --all
  • If the repo did not have LFS, success! Otherwise get a “misssing lfs objects” error

So, is there a way I can link these LFS objects back to their proper repos, given this setup? Perhaps this is more of an LFS question than a GitLab one, but I’m working with what I’ve got.