64

my basic disk is full for my gitlab installation, is it possible to move the repositories and their data to some other folder and make sure that the upcoming push's data is sent to those directories?

I tried stopping the gitlab and copying over the entire folder, but to no avail. PS - I am not an IT guy, I am just pitching in to see how could we get out of this issue; so please be verbose when answering.

Claudio
  • 9,427
  • 3
  • 28
  • 67
Brij Raj Singh - MSFT
  • 4,463
  • 6
  • 32
  • 54

6 Answers6

132

Just updating in case people still refer to this. From the GitLab documentation:

By default, omnibus-gitlab stores the Git repository data under /var/opt/gitlab/git-data. The repositories are stored in a subfolder repositories. You can change the location of the git-data parent directory by adding the following line to /etc/gitlab/gitlab.rb.

git_data_dirs({"default" => "/mnt/nas/git-data"})

Starting from GitLab 8.10 you can also add more than one git data directory by adding the following lines to /etc/gitlab/gitlab.rb instead.

git_data_dirs({
  "default" => "/var/opt/gitlab/git-data",
  "alternative" => "/mnt/nas/git-data"
})

Note that the target directories and any of its subpaths must not be a symlink.

Run sudo gitlab-ctl reconfigure for the changes to take effect.

If you already have existing Git repositories in /var/opt/gitlab/git-data you can move them to the new location as follows:

# Prevent users from writing to the repositories while you move them.
sudo gitlab-ctl stop

# Note there is _no_ slash behind 'repositories', but there _is_ a
# slash behind 'git-data'.
sudo rsync -av /var/opt/gitlab/git-data/repositories /mnt/nas/git-data/

# Fix permissions if necessary
sudo gitlab-ctl reconfigure

# Double-check directory layout in /mnt/nas/git-data. Expected output:
# gitlab-satellites  repositories
sudo ls /mnt/nas/git-data/

# Done! Start GitLab and verify that you can browse through the repositories in
# the web interface.
sudo gitlab-ctl start
Gus E
  • 2,071
  • 1
  • 21
  • 19
  • 1
    see also https://gitlab.com/gitlab-org/omnibus-gitlab/blob/629def0a7a26e7c2326566f0758d4a27857b52a3/README.md#storing-git-data-in-an-alternative-directory – Stéphane Jun 16 '15 at 08:20
  • 2
    Won't one need to start Postgres for gitlab-ctl reconfigure to work? – jeremiah Jul 04 '16 at 14:36
  • @Stéphane current link: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/configuration.md#storing-git-data-in-an-alternative-directory – Jürgen Steinblock Mar 20 '17 at 10:07
  • 1
    The `sudo gitlab-ctl reconfigure` command is VERY important, as not doing so will produces some 502 errors when navigating in GitLab or even worst. – SiZiOUS Jul 24 '18 at 15:32
  • What about single repo transfer? – Norman Edance Dec 19 '18 at 12:29
12

Much easier solution for new installs with the version > 7.14.1:

Open the gitlab.rb configuration file

sudo nano /etc/gitlab/gitlab.rb

Search for git_data_dir, uncomment the line and set your directory here, e.g.

git_data_dir "/storage/data/gitlab/git-data"

Save the file and reconfigure Gitlab:

sudo gitlab-ctl reconfigure
Kevin Woblick
  • 1,280
  • 1
  • 18
  • 33
5

I just moved my gitlab repositories folder from one directory to another, might be useful for someone (do this quickly at a quiet time or stop gitlab beforehand!)

Assuming you have a standard install the steps are

  • Create a new folder for repos as root and change the owner to the git user
  • Copy (with archive, recursive options) the old repo folder contents to its new home cp -ar SOURCE DESTINATION
  • Edit the gitlab config file and the gitlab-shell config files with the new repo path
  • Restart gitlab sudo /etc/init.d/gitlab restart
alastairtree
  • 3,114
  • 24
  • 39
  • I forgot to edit the gitlab-shell config.yml and my pushes were being denied by the hook, this helped me realize the problem, thx! – Roberto Sep 01 '14 at 04:39
  • Not working for wiki. UPD: for repository too. Am I doing something wrong? after cp -ar SOURCE* DESTINATION/ I delete in SOURCE forlder .git and .wiki.git – Norman Edance Dec 19 '18 at 10:53
3

If you're getting the cannot find repo error in GitLab after running the above steps. Run this command.

gitlab-rake cache:clear RAILS_ENV=production

This should fix the issue if your pathing is correct.

r0-
  • 1,967
  • 21
  • 28
Rusty
  • 31
  • 1
2

you need append this small config bellow:

git_data_dirs({
    "default" => {
        "path" => "/srv/gitlab/git-data"
    }
})

And

rsync -av /var/opt/gitlab/git-data/* /srv/gitlab/git-data/.
chown -R git:git /srv/gitlab/git-data/
sudo gitlab-ctl reconfigure

Done.

ThinhLP
  • 21
  • 2
1

In my case, I needed to move a repository from the default storage to storage1
If you load the project's general setting, it show the project number, for example 37:

sudo gitlab-rails console
irb(main):012:0> p37 = Project.find(37)
irb(main):009:0> p37.repository_storage
=> "default"
irb(main):010:0> p37.repository_storage = 'storage1'
irb(main):011:0> p37.save
=> true
irb(main):012:0>  # <ctrl>+d to send EOF and exit

clearing the cache is probably a good idea too

gitlab-rake cache:clear RAILS_ENV=production

ThorSummoner
  • 12,194
  • 11
  • 114
  • 129
  • 1
    Absolute lifesaver. I just moved a few repos over to a new drive and then had a moment of pure terror when I saw that 'this is a blank/empty repo' message. Found this and it fixed everything. thank you so much – Ironbelly Studios May 07 '20 at 16:29