在CentOS上对GitLab进行备份和恢复是一个重要的任务,以确保数据的安全性和业务的连续性。以下是详细的步骤:
备份
- 安装必要的依赖项:
sudo yum install -y curl policycoreutils-python openssh-server sudo systemctl enable sshd sudo systemctl start sshd sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --permanent --add-service=http sudo systemctl reload firewalld sudo yum install postfix sudo systemctl enable postfix sudo systemctl start postfix
- 安装GitLab:
sudo yum install gitlab-ce-版本号.rpm
- 配置GitLab备份:
- 编辑
/etc/gitlab/gitlab.rb
文件,设置备份路径和其他相关配置。 - 例如:
gitlab_rails['manage_backup_path'] = true gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" gitlab_rails['backup_archive_permissions'] = 0644 gitlab_rails['backup_keep_time'] = 7776000 # 备份保留天数,秒计算
- 保存文件并重新配置GitLab:
sudo gitlab-ctl reconfigure
- 创建备份:
sudo gitlab-rake gitlab:backup:create
- 定时备份:
- 使用
crontab -e
添加定时任务,例如每天凌晨2点执行备份:
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
恢复
- 停止GitLab服务:
sudo gitlab-ctl stop unicorn sudo gitlab-ctl stop sidekiq
- 恢复备份:
- 将备份文件拷贝到
/var/opt/gitlab/backups
目录。 - 停止数据连接服务(如果需要)。
- 执行恢复命令,使用备份编号:
sudo gitlab-rake gitlab:backup:restore BACKUP=备份编号
- 例如:
sudo gitlab-rake gitlab:backup:restore BACKUP=1577383292_2019_12_27_12.3.0
- 启动GitLab服务:
sudo gitlab-ctl start
注意事项
- 恢复操作时,确保两台主机的GitLab版本一致,否则可能会提示版本不匹配。
- 备份过程中会备份数据库、仓库、用户、用户组、用户密钥、权限等信息。
- 恢复前需要停止所有写入操作,以保证数据一致性。
以上步骤涵盖了在CentOS上对GitLab进行备份和恢复的基本流程。请根据实际情况调整配置和路径。