环境说明

原环境

  • Centos 7.2.1511
  • gitlab-ce-13.8.4-ce 安装方式 基于 rpm 包安装

新环境

  • Centos 8.5.2111
  • docker-compose 方式部署的 gitlab-ce:13.8.4-ce.0
  • Docker version 20.10.17
  • Docker Compose version v2.7.0

步骤说明

迁移的过程大致如下:

  1. 新旧服务器gitlab版本一致
  2. 备份旧服务器数据
  3. 还原数据到新服务器

Gitlab docker 版本查找

备份

备份命令

gitlab-rake gitlab:backup:create

过程


Creating backup archive: 1659683091_2022_08_05_13.8.4_gitlab_backup.tar ... done
Uploading backup archive to remote storage ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... skipping
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
Backup task is done.

备份文件在目录 /var/opt/gitlab/backups 中找到,传输到新环境中

还原

停止相关数据连接服务

root@gitlab:/var/opt/gitlab/backups# gitlab-ctl stop unicorn
root@gitlab:/var/opt/gitlab/backups# gitlab-ctl stop sidekiq

还原备份数据

gitlab-rake gitlab:backup:restore BACKUP=1659683091_2022_08_05_13.8.4

root@gitlab:/var/opt/gitlab/backups# gitlab-rake gitlab:backup:restore BACKUP=1659683091_2022_08_05_13.8.4
Unpacking backup ... done
Be sure to stop Puma, Sidekiq, and any other process that
connects to the database before proceeding. For Omnibus
installs, see the following link for more information:
https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installations

Before restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.

Do you want to continue (yes/no)? yes

询问 恢复数据库之前,我们将删除所有现有的 表,以避免将来的升级问题。 输入 yes

This task will now rebuild the authorized_keys file.
You will lose any data stored in the authorized_keys file.
Do you want to continue (yes/no)? yes

Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need to restore these files manually.
Restore task is done.
root@gitlab:/var/opt/gitlab/backups#

这个任务现在将重建authorized_keys文件。

您将丢失存储在authorized_keys文件中的所有数据。

是否继续(是/否)?

输入 yes

克隆地址修改

进入容器

docker-compose exec gitlab bash

or

docker exec -it gitlab bash

编辑配置

vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
host: 192.168.199.2
port: 8088
https: false

重启 gitlab

gitlab-ctl restart

常用命令

# 查看版本信息
gitlab-rake gitlab:env:info

# 创建备份
gitlab-rake gitlab:backup:create

# 恢复备份
gitlab-rake gitlab:backup:restore BACKUP=1571687782_2019_10_22_9.3.0

# 重新配置GitLab服务
gitlab-ctl reconfigure

# 检查GitLab服务状态
gitlab-rake gitlab:check

# 检查GitLab服务状态
gitlab-ctl status

# 停止所有GitLab服务
gitlab-ctl stop

# 重新启动所有GitLab服务
gitlab-ctl restart

# 可以通过在最后证明服务名称来重新启动特定服务
gitlab-ctl restart logrotate

# 查看所有的logs; 按 Ctrl-C 退出
sudo gitlab-ctl tail

# 拉取/var/log/gitlab下子目录的日志
sudo gitlab-ctl tail gitlab-rails

# 拉取某个指定的日志文件
sudo gitlab-ctl tail nginx/gitlab_error.log

# 查看hash存储项目数及附件数
gitlab-rake gitlab:storage:hashed_projects
gitlab-rake gitlab:storage:hashed_attachments

# 查看传统存储项目及附件数
gitlab-rake gitlab:storage:legacy_projects
gitlab-rake gitlab:storage:legacy_attachments

# 列出传统存储项目列表及附件列表
gitlab-rake gitlab:storage:list_legacy_projects
gitlab-rake gitlab:storage:list_legacy_attachments

问题解决

8 errors prohibited this user from being saved

尝试过网上的办法,进入容器修改root密码,无效

gitlab-rails console
u=User.where(id:1).first
u.password='12345678'
u.password_confirmation='12345678'
u.save
注意:root密码不能小于8位即12345678,不然会显示false

解决办法如下

删除容器

docker-compose rm gitlab

docker-compose.yml 文件增加 initial_root_password

environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
...
gitlab_rails['initial_root_password'] = '你要设置的root密码'
...

root@gitlab:/var/opt/gitlab/backups# gitlab-rake 1659683091_2022_08_05_13.8.4_gitlab_backup.tar
rake aborted!
Don't know how to build task '1659683091_2022_08_05_13.8.4_gitlab_backup.tar' (See the list of available tasks with `rake --tasks`)
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'
(See full trace by running task with --trace)

PG::ConnectionBad: could not connect to server: No such file or directory

PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432"?
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:27:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/backup.rake:69:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'
Tasks: TOP => gitlab:db:drop_tables
(See full trace by running task with --trace)

解决

重新启动 gitlab-ctl start

gitlab-ctl start
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

再执行备份

参考文献

Gitlab备份、迁移、恢复和升级

Compose specification

How do I start a gitlab-ce container via docker-compose with admin credentials already set up?