Reputation: 631
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).
Upvotes: 56
Views: 60337
Reputation: 1329092
2023+: the more recent process is called "direct transfert", introduced with GitLab 15.10 (March 2023):
Direct transfer migration on GitLab self-managed no longer requires feature flag
The open beta release of migrating GitLab projects with top-level groups by direct transfer meant GitLab self-managed users gained access to the beta feature.
However, instance administrators had to enable both:
- An application setting for migrating groups.
- The
bulk_import_projects
feature flag for migrating projects in the groups.In this release, we have removed the feature flag so you only need the application setting.
This change also enables GitLab Dedicated instances to take advantage of the feature.
See Documentation and Issue.
And, still with GitLab 15.10 (March 2023):
Improved import error messages that include subrelation errors
When migrating GitLab groups and projects, errors listed as import failures on the group Import history page were not always informative enough.
We now include errors from all nested subrelations to make it clear why a relation (for example, a merge request), failed to import.
Better error messages support debugging and speed up resolution time.See Documentation and Issue.
GitLab 15.11 (April 2023) makes the process more robust:
Better error message when direct transfer setting is disabled
GitLab group and project migration by direct transfer requires that both GitLab instances have the feature enabled in application settings by an instance administrator.
Until now, if you tried to initiate an import when the feature was disabled on the source instance, you received a
404
error.We’ve replaced the
404
error with an informative message, and provided guidance on how to enable the feature.See Documentation and Issue.
And GitLab 17.7 (December 2024) adds:
New user contribution and membership mapping available in direct transfer
The new method of user contribution and membership mapping is now available when you migrate between GitLab instances by direct transfer. This feature offers flexibility and control for both users managing the import process and users receiving contribution reassignments. With the new method, you can:
- Reassign memberships and contributions to existing users on the destination instance after the import has completed. Any memberships and contributions you import are first mapped to placeholder users. All contributions appear associated with placeholders until you reassign them on the destination instance.
- Map memberships and contributions for users with different email addresses on source and destination instances.
When you reassign a contribution to a user on the destination instance, the user can accept or reject the reassignment.
For more information, see streamline migrations with user contribution and membership mapping. To leave feedback, add a comment to issue 502565.
See Documentation and Epic.
2014 (original answer): 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
Upvotes: 8
Reputation: 6950
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
Upvotes: 38
Reputation: 6950
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.
Upvotes: 7
Reputation: 673
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'
Upvotes: 11