Migrating Gitlab packages from object store to local

I was having an infrastructure sort out and wanted to move my Gitlab packages from object storage hosted with MinIO back to Gitlab itself.

I managed to get Gitlab responding to the local storage again, for example, when it made a new package it didn't error out, however it wasn't able to find the tar.gz files for existing packages. When trying to download, I was faced with the following:

{
	"500 Internal server error"
}

First port of call was to resolve the permissions. Fortunately a Stack Overflow answer lead me to the Gitlab update permissions script.

This script has been great at solving some wrong permissions (and running this fixed a couple of other niggles I was having). However, this didn't resolve my issue.

I revisited the migration instructions on how to migrate to object storage and noticed some database commands near the bottom which, ultimately, solved the issue.

The steps I ran to migrate my Gitlab packages from object storage to local were:

  1. Copy the packages from the object storage, back to the default packages localted (keep the folder structure the same): /var/opt/gitlab/gitlab-rails/shared/packages/
  2. Connect to the database (be very careful) - this took a few seconds to connect for me: gitlab-rails dbconsole --database main
  3. Check the file_store location for the packages - 1 is local, 2 is object storage: select id,file_store,file from packages_package_files;

It was at this point I noticed all the packages (except a new one I had created) had a file_store of 2.

  1. Update one of the packages to check it now resolves update packages_package_files set file_store = 1 where id = 65;
  2. If successful, update all of the packages: update packages_package_files set file_store = 1;

P.s. Sorry for the overly verbose sentences and "keyword stuffing". I spent hours trying to resolve this the other day and figured if I save even 1 person the time, then it would have been worth it.

View this post on Github

You might also enjoy…

Mike Street

Written by Mike Street

Mike is a CTO and Lead Developer from Brighton, UK. He spends his time writing, cycling and coding. You can find Mike on Mastodon.