马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
×
1. 先决条件
-
必须还原/etc/gitlab/gitlab-secrets.json
-
若需要还原整台机器的TLS密钥,参见恢复密钥
-
选择从哪个备份恢复?
BACKUP=timestamp_of_backup :如果存在多个备份,则必选。阅读有关备份时间戳的信息。
force=yes :不询问是否应重新生成authorized_keys文件,并且对于删除数据库表,启用“写入authorized_keys文件”设置以及更新LDAP提供程序的警告,假设为“是”。
2. 恢复Omnibus GitLab安装
2.1 恢复前提
- 已经安装了与创建备份完全相同的版本和类型(CE / EE)的GitLab Omnibus。
- 已经运行过
sudo gitlab-ctl reconfigure 至少一次。
- GitLab正在运行。如果不是,请使用启动它
sudo gitlab-ctl start 。
2.2 准备备份文件
在 /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml 中可以找到backup.path位置。默认值为 /var/opt/gitlab/backups 。该目录归 git 用户所有。假设您的备份文件名为 1613723690_2021_02_19_13.8.0-ee_gitlab_backup.tar ,执行如下命令:
sudo cp 1613723690_2021_02_19_13.8.0-ee_gitlab_backup.tar /var/opt/gitlab/backups/
sudo chown git.git /var/opt/gitlab/backups/1613723690_2021_02_19_13.8.0-ee_gitlab_backup.tar
2.3 停止所有连接到数据库的进程
sudo gitlab-ctl stop unicorn || sudo gitlab-ctl stop puma
sudo gitlab-ctl stop sidekiq
# Verify
sudo gitlab-ctl status
2.4 还原数据
进入http://your_gitlab_ip/admin,查看当前Gitlab版本。
- 如果是GitLab 12.2 或更新版本,执行如下命令:
# 这条命令会覆盖GitLab数据库的内容!注意和文件名的结尾有区别,结尾没有`gitlab_backup`,只到`ee`:
sudo gitlab-backup restore BACKUP=1613723690_2021_02_19_13.8.0-ee
- 如果是GitLab 12.1 或更旧版本,执行如下命令:
gitlab-rake gitlab:backup:restore
注意:如果是恢复数据到HA高可用集群,需要绕过 Pgbouncer ,使用环境变量 GITLAB_BACKUP_PG* 指定数据库连接信息:
sudo GITLAB_BACKUP_PGHOST=192.168.1.10 GITLAB_BACKUP_PGPORT=5432 GITLAB_BACKUP_PGUSER=gitlab-psql gitlab-backup restore BACKUP=1613723690_2021_02_19_13.8.0-ee
另外Gitaly集群需要 只保留一台,其余关闭 ,加快导入仓库的速度,否则仓库导入速度会比较慢(Gitaly节点之间会在导入的时候进行数据同步)。待导入完成后,再启动关闭的gitaly节点。
注意: GitLab12.1或更旧版本,执行还原后会引起一个问题。用如下方式解决:
sudo chown -R registry:registry /var/opt/gitlab/gitlab-rails/shared/registry
2.5 还原配置
假设备份的配置文件 gitlab_config_1613725002_2021_02_19.tar 已经放在了/tmp/restore目录下
cd /tmp/restore
# 解压
tar -xvf gitlab_config_1613725002_2021_02_19.tar
# 权限指给root
sudo chown -R root:root etc
# 备份原来的/etc/gitlab目录
sudo cp -r /etc/gitlab /tmp/restore/old_config
# 覆盖/etc/gitlab/gitlab.rb
sudo cp -r /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb
# 覆盖/etc/gitlab/gitlab-secrets.json
sudo cp -r etc/gitlab/gitlab-secrets.json /etc/gitlab/gitlab-secrets.json
**注意:**如果是恢复数据到HA高可用集群,需要覆盖所有Rails节点和Gitaly节点的`gitlab-secrets.json`。
2.6 生效配置,重启并检查GitLab
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
sudo gitlab-rake gitlab:check SANITIZE=true
注意: 执行完restart之后,要稍等一会等所有内部服务全部启动完成后,再进行check验证。
-
如果GitLab版本在13.1及更高版本时,可以对数据库中的值进行解密。验证当前的配置文件(gitlab-secrets.json )是否正确,执行如下命令:
sudo gitlab-rake gitlab:doctor:secrets
可能的输出如下:
I, [2021-02-20T07:35:02.024050 #18077] INFO -- : Checking encrypted values in the database
I, [2021-02-20T07:35:11.367196 #18077] INFO -- : - ApplicationSetting failures: 0
I, [2021-02-20T07:35:11.462137 #18077] INFO -- : - User failures: 0
I, [2021-02-20T07:35:11.472080 #18077] INFO -- : - GeoNode failures: 0
I, [2021-02-20T07:35:11.488017 #18077] INFO -- : - Ci::InstanceVariable failures: 0
I, [2021-02-20T07:35:11.498654 #18077] INFO -- : - Clusters::Platforms::Kubernetes failures: 0
I, [2021-02-20T07:35:11.510358 #18077] INFO -- : - Ci::PipelineScheduleVariable failures: 0
I, [2021-02-20T07:35:11.520338 #18077] INFO -- : - Snippet failures: 0
I, [2021-02-20T07:35:11.527921 #18077] INFO -- : - PersonalSnippet failures: 0
I, [2021-02-20T07:35:11.530048 #18077] INFO -- : - ProjectSnippet failures: 0
I, [2021-02-20T07:35:11.541204 #18077] INFO -- : - Ci::GroupVariable failures: 0
I, [2021-02-20T07:35:11.552699 #18077] INFO -- : - Clusters::Applications::Helm failures: 0
I, [2021-02-20T07:35:11.563794 #18077] INFO -- : - Clusters::Applications::Prometheus failures: 0
I, [2021-02-20T07:35:11.575466 #18077] INFO -- : - Ci::Variable failures: 0
I, [2021-02-20T07:35:11.587385 #18077] INFO -- : - AlertManagement::HttpIntegration failures: 0
I, [2021-02-20T07:35:11.598141 #18077] INFO -- : - Alerting::ProjectAlertingSetting failures: 0
I, [2021-02-20T07:35:11.609403 #18077] INFO -- : - Atlassian::Identity failures: 0
I, [2021-02-20T07:35:11.620764 #18077] INFO -- : - BulkImports::Configuration failures: 0
I, [2021-02-20T07:35:11.631816 #18077] INFO -- : - Ci::JobVariable failures: 0
I, [2021-02-20T07:35:11.643073 #18077] INFO -- : - Ci::PipelineVariable failures: 0
I, [2021-02-20T07:35:11.656235 #18077] INFO -- : - Clusters::KubernetesNamespace failures: 0
I, [2021-02-20T07:35:11.667584 #18077] INFO -- : - Clusters::Providers::Aws failures: 0
I, [2021-02-20T07:35:11.688009 #18077] INFO -- : - Clusters::Providers::Gcp failures: 0
I, [2021-02-20T07:35:11.699357 #18077] INFO -- : - ErrorTracking::ProjectErrorTrackingSetting failures: 0
I, [2021-02-20T07:35:11.711290 #18077] INFO -- : - GrafanaIntegration failures: 0
I, [2021-02-20T07:35:11.724644 #18077] INFO -- : - WebHook failures: 0
I, [2021-02-20T07:35:11.726962 #18077] INFO -- : - ProjectHook failures: 0
I, [2021-02-20T07:35:11.729547 #18077] INFO -- : - ServiceHook failures: 0
I, [2021-02-20T07:35:11.731483 #18077] INFO -- : - SystemHook failures: 0
I, [2021-02-20T07:35:11.733684 #18077] INFO -- : - GroupHook failures: 0
I, [2021-02-20T07:35:11.744404 #18077] INFO -- : - IncidentManagement::ProjectIncidentManagementSetting failures: 0
I, [2021-02-20T07:35:11.755105 #18077] INFO -- : - JiraConnectInstallation failures: 0
I, [2021-02-20T07:35:11.768162 #18077] INFO -- : - Packages::Debian::GroupDistribution failures: 0
I, [2021-02-20T07:35:11.781874 #18077] INFO -- : - Packages::Debian::ProjectDistribution failures: 0
I, [2021-02-20T07:35:11.792846 #18077] INFO -- : - PagesDomain failures: 0
I, [2021-02-20T07:35:11.805954 #18077] INFO -- : - PagesDomainAcmeOrder failures: 0
I, [2021-02-20T07:35:11.817961 #18077] INFO -- : - ProjectImportData failures: 0
I, [2021-02-20T07:35:11.832488 #18077] INFO -- : - IssueTrackerData failures: 0
I, [2021-02-20T07:35:11.846288 #18077] INFO -- : - JiraTrackerData failures: 0
I, [2021-02-20T07:35:11.862346 #18077] INFO -- : - OpenProjectTrackerData failures: 0
I, [2021-02-20T07:35:11.876823 #18077] INFO -- : - RemoteMirror failures: 0
I, [2021-02-20T07:35:11.890519 #18077] INFO -- : - Serverless::DomainCluster failures: 0
I, [2021-02-20T07:35:11.892265 #18077] INFO -- : - Gitlab::BackgroundMigration::BackfillJiraTrackerDeploymentType2::JiraTrackerDataTemp failures: 0
I, [2021-02-20T07:35:11.893714 #18077] INFO -- : - Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData::IssueTrackerData failures: 0
I, [2021-02-20T07:35:11.895827 #18077] INFO -- : - Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData::JiraTrackerData failures: 0
I, [2021-02-20T07:35:11.909634 #18077] INFO -- : - StatusPage::ProjectSetting failures: 0
I, [2021-02-20T07:35:12.038309 #18077] INFO -- : - Group failures: 0
I, [2021-02-20T07:35:12.061404 #18077] INFO -- : - Ci::Build failures: 0
I, [2021-02-20T07:35:12.074547 #18077] INFO -- : - Ci::Runner failures: 0
I, [2021-02-20T07:35:12.091572 #18077] INFO -- : - DeployToken failures: 0
I, [2021-02-20T07:35:12.346693 #18077] INFO -- : - Project failures: 0
I, [2021-02-20T07:35:12.362114 #18077] INFO -- : - Clusters::AgentToken failures: 0
I, [2021-02-20T07:35:12.376103 #18077] INFO -- : - Operations::FeatureFlagsClient failures: 0
I, [2021-02-20T07:35:12.390144 #18077] INFO -- : - ScimOauthAccessToken failures: 0
I, [2021-02-20T07:35:12.390226 #18077] INFO -- : Total: 0 row(s) affected
I, [2021-02-20T07:35:12.390241 #18077] INFO -- : Done!
2.7 当配置文件丢失时
如果没有备份旧的配置文件,那么需要手工重置很多组件的令牌。参见
当机密文件丢失时,使用其中的信息,后果自负。 |