Skip to content

1.备份 gitlab-ce 数据

bash
gitlab-rake gitlab:backup:create
gitlab-rake gitlab:backup:create

备份文件保存在/var/opt/gitlab/backups/目录下,使用工具将文件下载上传至目标服务器的/var/opt/gitlab/backups/目录

2.使用原 gitlab-ce 备份数据进行恢复

bash
cd /var/opt/gitlab/backups/
# 将权限修改为git用户
chown git 1551144361_2019_02_26_11.6.5_gitlab_backup.tar



#停止数据写入服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

#查看状态
gitlab-ctl status

# 执行还原操作
gitlab-rake gitlab:backup:restore BACKUP=1551144361_2019_02_26_11.6.5

#重启服务
 gitlab-ctl restart
cd /var/opt/gitlab/backups/
# 将权限修改为git用户
chown git 1551144361_2019_02_26_11.6.5_gitlab_backup.tar



#停止数据写入服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

#查看状态
gitlab-ctl status

# 执行还原操作
gitlab-rake gitlab:backup:restore BACKUP=1551144361_2019_02_26_11.6.5

#重启服务
 gitlab-ctl restart

3. gitlab-ee备份

cd /var/opt/gitlab/backups/
# 将权限修改为git用户
chown git 1725604415_2024_09_06_16.0.0-ee_gitlab_backup.tar



#停止数据写入服务
gitlab-ctl stop puma
gitlab-ctl stop sidekiq

#查看状态
gitlab-ctl status

# 执行还原操作
修改名字
mv 1725604415_2024_09_06_16.0.0-ee_gitlab_backup.tar 1725604415_gitlab_backup.tar

gitlab-rake gitlab:backup:restore BACKUP=1725604415
cd /var/opt/gitlab/backups/
# 将权限修改为git用户
chown git 1725604415_2024_09_06_16.0.0-ee_gitlab_backup.tar



#停止数据写入服务
gitlab-ctl stop puma
gitlab-ctl stop sidekiq

#查看状态
gitlab-ctl status

# 执行还原操作
修改名字
mv 1725604415_2024_09_06_16.0.0-ee_gitlab_backup.tar 1725604415_gitlab_backup.tar

gitlab-rake gitlab:backup:restore BACKUP=1725604415

❌ 注意

迁移必须保持版本号一致,否则还原会失败

3.1 容器下备份

bash
docker exec -it gitlab-ee gitlab-rake gitlab:backup:create
docker exec -it gitlab-ee gitlab-rake gitlab:backup:create

3.2 容器下恢复

bash
docker exec -it gitlab-ee gitlab-rake gitlab:backup:restore BACKUP=<backup-timestamp>
docker exec -it gitlab-ee gitlab-rake gitlab:backup:restore BACKUP=<backup-timestamp>