Issues with comments, merge requests with diffs and comments, labels, milestones, snippets, time tracking, and other project entities
Design Management files and data
LFS objects
Issue boards
Pipelines history
Push Rules
Awards
Group members are exported as project members, as long as the user has the Maintainer role in the exported project’s group, or is an administrator
The following items are not exported:
Child pipeline history
Build traces and artifacts
Package and container registry images
CI/CD variables
Pipeline triggers
Webhooks
Any encrypted tokens
Merge Request Approvers and the number of required approvals
Repository size limits
Deploy keys allowed to push to protected branches
Secure Files
These content rules also apply to creating projects from templates on the group or instance levels, because the same export and import mechanisms are used.
2.导入导出过程
导出
On the top bar, select Menu > Projects and find your project.
On the left sidebar, select Settings > General.
Expand Advanced.
Select Export project.
After the export is generated, you should receive an email with a link to download the file.
Alternatively, you can come back to the project settings and download the file from there or generate a new export. After the file is available, the page should show the Download export button.
导入
When creating a new project, select Import project.
In Import project from, select GitLab export.
Enter your project name and URL. Then select the file you exported previously.
Select Import project to begin importing. Your newly imported project page appears shortly.
方式二:Gitlab backup & restore
根据官方文档说,单个gitlab之间数据的迁移,这是最推荐的方式。
优点:
流程简单,依赖于Gitlab自带工具;
从Gitlab v14.9 开始支持增量数据备份与恢复;
可以根据需要,选择备份与恢复的内容;
缺点:
不支持多个Gitlab到一个Gitlab的数据同步;
恢复时可能会产生数据覆盖,也就是恢复的Gitlab最好是一个空的Gitlab;
同样受限于版本,只支持相同版本Gitlab之间的backup & restore ,You can only restore a backup to exactly the same version and type (CE/EE) of GitLab that you created it on;
不能直接识别使用对象存储保存的项目,需要工具转换为文件存储;
1.backup
GitLab provides a command line interface to back up your entire instance, including:
# Install gitlab by using the Omnibus package
## Gitlab 12.2 or later
sudo gitlab-backup create
## Gitlab 12.1 and earlier
sudo gitlab-rake gitlab:backup:create
# Install gitlab from source
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
1
2
3
4
5
6
7
8
9
10
额外需要备份文件
The backup Rake task GitLab provides does not store your configuration files. The primary reason for this is that your database contains items including encrypted information for two-factor authentication and the CI/CD secure variables. Storing encrypted information in the same location as its key defeats the purpose of using encryption in the first place.
For Omnibus:
/etc/gitlab/gitlab-secrets.json
/etc/gitlab/gitlab.rb
For installation from source:
/home/git/gitlab/config/secrets.yml
/home/git/gitlab/config/gitlab.yml
Backup options
具体参考
The command line tool GitLab provides to backup your instance can accept more options.
backup strategy option STRATEGY=copy
## For Omnibus GitLab packages
sudo gitlab-backup create STRATEGY=copy
## For installations from source
sudo -u git -H bundle exec rake gitlab:backup:create STRATEGY=copy RAILS_ENV=production
1
2
3
4
5
bakcup filename BACKUP=
confirm archive can be transferred GZIP_RSYNCABLE=yes
Excluding specific directories from the backup SKIP=
You can exclude specific directories from the backup by adding the environment variable SKIP, whose values are a comma-separated list of the following options:
db (database)
uploads (attachments)
builds (CI job output logs)
artifacts (CI job artifacts)
lfs (LFS objects)
terraform_state (Terraform states)
registry (Container Registry images)
pages (Pages content)
repositories (Git repositories data)
packages (Packages)
# skip db and uploads
## For Omnibus GitLab packages
sudo gitlab-backup create SKIP=db,uploads
## For installations from source
sudo -u git -H bundle exec rake gitlab:backup:create SKIP=db,uploads RAILS_ENV=production
1
2
3
4
5
6
7
Disabling prompts during restore GITLAB_ASSUME_YES=1
Back up Git repositories concurrently
Introduced in GitLab 13.3
When using multiple repository storages, repositories can be backed up or restored concurrently to help fully use CPU time.
GITLAB_BACKUP_MAX_CONCURRENCY: The maximum number of projects to back up at the same time. Defaults to the number of logical CPUs (in GitLab 14.1 and earlier, defaults to 1).
GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY: The maximum number of projects to back up at the same time on each storage. This allows the repository backups to be spread across storages. Defaults to 2 (in GitLab 14.1 and earlier, defaults to 1).
Introduced in GitLab 14.9 with a flag named incremental_repository_backup. Disabled by default
PREVIOUS_BACKUP option introduced in GitLab 15.0
Back up specific repository storages REPOSITORIES_STORAGES=
ntroduced in GitLab 15.0
Uploading backups to a remote (cloud) storage
2.Restore
Prerequisites
You need to have a working GitLab installation before you can perform a restore. This is because the system user performing the restore actions (git) is usually not allowed to create or delete the SQL database needed to import data into (gitlabhq_production). All existing data is either erased (SQL) or moved to a separate directory (such as repositories and uploads). 数据库相关
To restore a backup, you must restore /etc/gitlab/gitlab-secrets.json (for Omnibus packages) or /home/git/gitlab/.secret (for installations from source). This file contains the database encryption key, CI/CD variables, and variables used for two-factor authentication. If you fail to restore this encryption key file along with the application data backup, users with two-factor authentication enabled and GitLab Runner loses access to your GitLab server. 密钥
You may also want to restore your previous /etc/gitlab/gitlab.rb (for Omnibus packages) or /home/git/gitlab/config/gitlab.yml (for installations from source) and any TLS keys, certificates (/etc/gitlab/ssl, /etc/gitlab/trusted-certs), or SSH host keys. 配置文件
Starting with GitLab 12.9, if an untarred backup (like the ones made with SKIP=tar) is found, and no backup is chosen with BACKUP=, the untarred backup is used.
Command
# Restore for installation from source
## Stop processes that are connected to the database
sudo service gitlab stop
## restore
sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=production
Rake tasks are available to import bare repositories into a GitLab instance. When migrating from an existing GitLab instance, and to preserve ownership by users and their namespaces, please use our project-based import/export. 也就是使用方式一。
注意事项:
The owner of the project is the first administrator.
The groups are created as needed, including subgroups.
The owner of the group is the first administrator.
Existing projects are skipped.
Projects in hashed storage may be skipped. For more information, see Importing bare repositories from hashed storage. 从Gitlab 10.0开始引入hashed storage,12.0之后作为默认存储方式,不过迁移方式类似
The existing Git repositories ware moved from disk (removed from the original path).
Congregate is a migration tool that can move data from many different Source Code Management (SCM) and Continuous Integration (CI) systems into a GitLab Self Managed (SM) instance hosted in the customer data center/cloud or GitLab.com. It is what GitLab Professional Services uses for large scale migration engagements. It is being shared in a source-available way for collaboration with Customers and Partners.