GitLab 数据备份与恢复

GitLab 备份

1
2
# 可以将此命令写入crontab,以实现定时备份
/usr/bin/gitlab-rake gitlab:backup:create

备份的数据会存储在 /var/opt/gitlab/backups ,除非用户在 gitlab_rails['backup_path'] 另行设定:

1
2
3
4
5
[root@hzz ~]# ls -l /var/opt/gitlab/backups
total 24667228
-rw------- 1 git git 12384215040 Oct 19 12:39 1476851754_gitlab_backup.tar
-rw------- 1 git git 506798080 Oct 19 12:43 1476852184_gitlab_backup.tar
-rw------- 1 git git 12368209920 Oct 20 02:17 1476900742_gitlab_backup.tar

GitLab 恢复

1
2
3
4
5
6
7
8
9
10
11
12
# 停止unicorn和sidekiq,保证数据库没有新的连接,不会有写数据情况
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq

# 进入备份目录进行恢复,1476900742为备份文件的时间戳
cd /var/opt/gitlab/backups
gitlab-rake gitlab:backup:restore BACKUP=1476900742
cd -

# 启动unicorn和sidekiq
sudo gitlab-ctl start unicorn
sudo gitlab-ctl start sidekiq