54

Just installed a fresh new 6.8 Gitlab on a brand new high performance server.

Before considering to forget my repositories history (comments, issues, etc...), do one know of a way to export a repository data from a Gitlab server to another Gitlab Server ?

I just failed to found anything on the documentation for exporting/migrating the whole project data (not just the git repository and its wiki).

4 Answers 4

37

For GitLab versions >= 8.9 (released in June 2016) you can use the built-in export and import project feature.

Please not that for the existing installations of GitLab, this option has to be enabled in the application settings (URL: /admin/application_settings) under 'Import sources'. You have to be a GitLab admin user to enable and use the import functionality.

Here is the feature complete documentation: https://gitlab.com/help/user/project/settings/import_export.md

8
  • 3
    This one should be the accepted answer. Here is more information: gitlab.com/help/user/project/settings/import_export.md
    – Cristian T
    Commented Aug 13, 2016 at 7:37
  • Thanks @CristianT! I have also added the link to my answer. Commented Aug 14, 2016 at 18:12
  • 1
    It looks like the import options have changed: gitlab is not listed ! I noe see GitHub, Bitbucket, Google Code, Fogbugz, git repo Commented Sep 15, 2016 at 13:11
  • Maybe you haven't enabled it in /admin/application_settings, @SomeoneSomewhere? I have added that to my answer. Commented Sep 15, 2016 at 13:41
  • thanks for your fast response. I can't find the setting and using https://gitlab.com/admin/application_settings results in a 404. Is it something like Burger Menu -> Profile Settings -> Applications ? Commented Sep 15, 2016 at 19:57
11

I have actually done this recently, we were upgrading our instance of gitlab and needed to save and import repositories to the new installation.

First, create a bundle of the checked-out repository. For example, say you checked out a repository we will call myrepository

To check out the repository use git clone (let's assume your repository is under the root account and the ipaddress is 192.168.1.1)

git clone http://192.168.1.1/root/myrepository.git (or match your environment)

Now this step is somewhat important; you need to change into the working directory that has the .git folder of your checked out repository.

cd myrepository

Next, you create a bundle file:

git bundle create myrepository.bundle --all

Import the bundle file into the new instance of gitlab.

Create a new 'myrepository' on the gitlab gui interface

clone the empty repository; let's say this new gitlab has the ipaddress 192.168.1.2:

git clone http:\\192.168.1.2\root\myrepository.git (or match your environment)

You will get warnings that you cloned an empty repository. This is normal.

Change into the working directory of your checked out repository and do a git pull:

cd myrepository

git pull file/path/to/myrepository.bundle

this will pull the repository into your clone. Next you can do a git add, git commit and git push

This should work assuming you have the gitlab server settings set up correctly; you may have issues such as needing to add a client_max_body_size parameter in your nginx.conf file and also a 'git config --global http.postBuffer' to push large files.

Another way to do this is to make patch files of each commit and then deploy them:

This involves doing a 'git format-patch -C 0badil..68elid -o patch_directory_path' and reference the range of all your commits and have them pushed to an output directory; this should give you one patch file per commit. Next would involve git cloning the new empty repository, changing into the working directory of the clone and applying the patches to the new repository using 'git am patch_directory_path'

2
  • 16
    I don't get the many upvotes. If you have big gitlab server, with lots of users, projects etc. this answer doesn't help in the slightest. The issue here isn't the repo itself, which, as you can see per this answer, is really easy to push to somewhere else (git clone --mirror then git push --mirror, no need for all the fluff in this answer), the issue is setting up all those users, all those repos, all the matching permissions, all the issues, etc., nothing of which is being addressed here
    – Cookie
    Commented Jul 20, 2016 at 15:38
  • Well, this is the hard way. You cannot just move part of data on the filesystem, you need to upgrade the GitLab properly in order to perform all the database upgrade (rake) tasks while not loosing all the precious data along the way.
    – igraczech
    Commented Jul 28, 2017 at 22:53
8

For the repos themselves, you can use git bundle: that will generate one file, that it is easy to copy around.
(as I described in "Backup a Local Git Repository")

But another way is simply to git clone --mirror your repos from the first server on a local workstation, and git push --mirror to the new server.
This is what GitHub details in its help page "Duplicating a repository".

In both cases, you need first to declare those repos on the new GitLab server, in order for them to be initialized, and ready to receive commits.


But for the rest... not easily. There is a feature request pending:
(Update August 2016, 2 years later: GitLab 8.9 has that feature implemented)
(for GitLab version older than 8.9, see and upvote Greg Dubicki's answer)

I agree that issues are the main thing to make exportable first.
They are stored in the database. Storing them in git is not an option. Maybe export them as a formatted file (SQL, YAML or something else).

This blog post illustrates the export of a mysql database.

Use mysqldump to create dump of old database, then create a new database on the new server and import this.

  • On old:
    mysqldump gitlab | gzip > gitlab.sql.gz
  • On new:
    gunzip < gitlab.sql.gz | mysql gitlab

Run the db migrate command to make sure the schema is updated to the latest version.

sudo -u gitlab -H bundle exec rake db:migrate RAILS_ENV=production
6
  • i'm not sure you understood, that would export my repositories, but not their issues, comments on code, comments on merge request, etc... Commented Apr 25, 2014 at 14:30
  • @blackeyedboy i have edited my answer with the relevant feature request.
    – VonC
    Commented Apr 25, 2014 at 14:33
  • damn, i forgot searching on their suggestion forum ! thanks for the link Commented Apr 25, 2014 at 14:34
  • thanks, but it says from version 3.1 to 4.1, we are currently 6.8 and gitolite is no more used by gitlab since 5.0 Commented Apr 25, 2014 at 14:37
  • @blackeyedboy it doesn't matter. The version isn't what is important here: the process would remain the same: dumping and re-importing the database.
    – VonC
    Commented Apr 25, 2014 at 14:38
7

For GitLab versions < 8.9, without built-in export/import feature, I recommend a great tool from Marcus Chmelar, gitlab-migrator. I used it successfully many times with older GitLab versions so you should too. Just be aware of its limitations.

Not the answer you're looking for? Browse other questions tagged or ask your own question.