在Debian系统上进行GitLab备份与恢复的流程如下:
准备工作:
gitlab-ctl stop
。创建备份:
gitlab-rake gitlab:backup:create
命令来创建备份。此命令会在默认路径 /var/opt/gitlab/backups
下生成一个包含所有GitLab数据的备份文件。修改默认存储路径(可选):
/etc/gitlab/gitlab.rb
文件来修改默认的备份存储路径。sudo vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] '/data/gitlab/backups'
修改后,需要运行 sudo gitlab-ctl reconfigure
重新配置GitLab。
定时备份与删除旧备份(可选):
/var/opt/gitlab/backups/gitlabbak.sh
,用于定期执行备份并删除10天之前的备份文件。#!/bin/bash
/opt/gitlab/bin/gitlab-rake gitlab:backup:create
sleep 10
find /var/opt/gitlab/backups -name "*.tar" -type f -mtime 10 -exec rm -rf {} \;
0 8 * * 1,3,5 /bin/sh /var/opt/gitlab/backups/gitlabbak.sh /dev/null 2&1
准备工作:
gitlab-ctl stop
。恢复数据库:
tar -xzf gitlab_backup.tar.gz
。gitlab-rake gitlab:backup:restore BACKUP
命令恢复数据库,其中 BACKUP
是备份文件名。恢复仓库文件:
cp -r repositories/* /var/opt/gitlab/git-data/repositories/
。启动GitLab服务:
gitlab-ctl start
命令启动GitLab服务。验证恢复结果:
通过以上步骤,可以有效地对Debian系统上的GitLab进行备份和恢复,确保数据的安全性和可恢复性。