
gitlab/gitlab-ce: 为社区版
gitlab/gitlab-ee:为企业版
version: '3.6'
services:
gitlab-web:
image: 'gitlab/gitlab-ce:15.9.2-ce.0'
restart: always
hostname: '10.10.1.110'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://10.10.1.110:8929'
gitlab_rails['gitlab_shell_ssh_port'] = 2224
ports:
- '8929:8929'
- '2224:22'
volumes:
- './config:/etc/gitlab'
- './logs:/var/log/gitlab'
- './data:/var/opt/gitlab'
shm_size: '512m'
备份迁移的时候需要一样的gitlab版本,否则备份恢复会失败
先备份文件, 通过gitlab-rake命令备份gitlab
gitlab-rake gitlab:backup:create
使用以上命令会在/var/opt/gitlab/backups目录下创建一个名称类似为1530156812_2023_05_25_15.9.2_gitlab_backup.tar的压缩包,
这个压缩包就是Gitlab整个的完整部分, 其中开头的1530156812\_2018\_06\_28\_10.8.4是备份创建的日期;备份恢复
复制备份文件到备份目录
/data/wwwroot/gitlab/data/backups
gitlab-rake gitlab:backup:restore BACKUP=备份版本号
gitlab-rake gitlab:backup:restore BACKUP=1698888491_2023_11_02_15.9.2gitlab-rake gitlab:backup:restore BACKUP=1701765310_2023_12_05_15.9.2
一、背景 去年做GitLab数据迁移时,写过一篇文章《GitLab的备份与还原》。后来发现新创建的项目没问题,但对于迁移过来的项目,修改名称等信息,或者删除该项目时,会出现500错误,以为是系统问题,一直也查到解决办法。
二、缘由 前段时间再次搜索解决办法,终于解决了,在这里记录一下。
导致这样的缘由,了解到是db_key_base参数出现了问题。db_key_base是一个64位随机字符串,它用于为应用程序生成安全的密钥。原先的密钥没复制过来,导致修改原项目时验证无法通过。三、解决办法 原先的GitLab早就删除干净了,原先的db_key_base自然也找不回来,只好重置所有的密钥和token。
1、进入数据库控制台 命令行输入:
gitlab-rails dbconsole需要注意的是,在使用gitlab-rails dbconsole时,请务必超级小心。由于您将直接操作GitLab使用的数据库,所以错误的SQL语句有可能导致数据丢失或损坏。
2、重置SQL数据库中的Token
gitlab-psql -d gitlabhq_production然后依次输入一下命令 :
# 将所有项目的runners_token和runners_token_encrypted字段设置为null。
UPDATE projects SET runners_token = null, runners_token_encrypted = null;
# 将所有命名空间(例如用户或组)的runners_token和runners_token_encrypted字段设置为null。
UPDATE namespaces SET runners_token = null, runners_token_encrypted = null;
# 将GitLab应用程序设置中的runners_registration_token_encrypted字段设置为null。
UPDATE application_settings SET runners_registration_token_encrypted = null;然后输入q或者exit退出。
3、重启GitLab
gitlab-ctl restart至此整个Gitlab已经恢复正常,原先的项目可以改名,也可以删除了。