GitLab数据备份与恢复

数据备份

备份时需要保持gitlab处于正常运行状态,通过执行gitlab-rake gitlab:backup:create进行备份

默认备份文件会存在在/var/opt/gitlab/backups目录下,备份的文件是个tar包,包含了GitLab的所有数据(账户、仓库等)。

例如:1589357414_2020_05_13_10.2.2_gitlab_backup.tar
1589357414是一个时间戳(即,从1970年1月1日0时到当前时间的秒数)
  • 备份前,先拉取远程仓库gitlab上的代码文件到本地仓库,以同步本地仓库的项目
#拉取代码到本地仓库
[root@git git_test]# git pull git@10.0.0.91:Dev/test.git
remote: Counting objects: 40, done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 40 (delta 12), reused 40 (delta 12)
Unpacking objects: 100% (40/40), done.
From 10.0.0.91:Dev/test
 * branch            HEAD       -> FETCH_HEAD
[root@git git_test]# 
  • 修改gitlab配置文件
#修改以下配置(根据需要修改)
[root@git git_test]# vim /etc/gitlab/gitlab.rb 
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/backup/gitlab"
gitlab_rails['backup_archive_permissions'] = 0644
gitlab_rails['backup_keep_time'] = 604800

#重新加载配置
[root@git git_test]# gitlab-ctl reconfigure
  • 创建备份
#备份
[root@git git_test]# gitlab-rake gitlab:backup:create

#查看下备份后的文件
[root@git git_test]# ll /data/backup/gitlab/
1589357414_2020_05_13_10.2.2_gitlab_backup.tar

数据恢复

如果我们是迁移GitLab的话,即在另外一台主机上恢复数据。

需要将备份文件拷贝到目标主机的/var/opt/gitlab/backups目录下(备份和恢复的GitLab版本尽量爆出一致,避免发生错误)

  • 停止gitlab上相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
  • 从备份文件恢复数据

从指定备份文件编号1589357414_2020_05_13_10.2.2恢复(当有多个备份文件时)

gitlab-rake gitlab:backup:restore BACKUP=1589357414_2020_05_13_10.2.2

恢复过程中,按照提示输入2次yes并回车,完成备份。

  • 重启gitlab服务
gitlab-ctl restart

访问web界面,可以看到GItLab已经迁移(备份恢复)成功。

点赞

发表回复