'gitlab-ce 12.X : how do I find the hashed storage path of a repository on the server?
With gitlab-ce-12.x, Geo requires the storage path to be hashed (https://docs.gitlab.com/ee/administration/repository_storage_types.html)
For a given repository, the data will therefore be stored in : "@hashed/#{hash[0..1]}/#{hash[2..3]}/#{hash}.git"
From a practical point of view, say I have a repository whose URL is
How do I work out the path to the storage on the server ? i.e. how do i find the value of
#{hash[0..1]}/#{hash[2..3]}/#{hash}
Thanks
Solution 1:[1]
I found the answer to my question.
In order to get the hashed storage location of a project, you first need to get the project id of the project repository.
Once you get that project id, say your project id is 1, you get the hash this way :
Say project.id is 1
echo -n 1 | sha256sum
=> You get the HASH 6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
The hashed storage location of your repository on the server will therefore be :
server/@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.git
This has been discussed by gitlab developers in https://gitlab.com/gitlab-org/gitlab-ce/issues/63250
Solution 2:[2]
As @iclman describes, and since then documented you can calculate the hashed storage path from the sha256 hash of the project ID. Here is how you can do this with Ruby:
proj_id = '<PROJECT_ID>'
hash = Digest::SHA2.new(256).hexdigest proj_id
"/var/opt/gitlab/git-data/repositories/@hashed/#{hash[0..1]}/#{hash[2..3]}/#{hash}.git"
Or with a shell function (bash/zsh):
get-gitlab-project-path() {
PROJECT_HASH=$(echo -n $1 | openssl dgst -sha256 | sed 's/^.* //')
echo "/var/opt/gitlab/git-data/repositories/@hashed/${PROJECT_HASH:0:2}/${PROJECT_HASH:2:2}/${PROJECT_HASH}.git"
}
Fish shell function:
function get-project-path --description 'Print the GitLab hashed storage path of a project ID'
set PROJECT_HASH (echo -n $argv[1] | openssl dgst -sha256 | string trim)
set B1 (string sub --start=1 --length=2 $PROJECT_HASH)
set B2 (string sub --start=3 --length=2 $PROJECT_HASH)
set HASHED_DIR "/var/opt/gitlab/git-data/repositories/@hashed"
echo $HASHED_DIR/$B1/$B2/$PROJECT_HASH.git
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | iclman |
Solution 2 | mike |