在 CentOS 上使用 Omnibus 包部署的 GitLab,备份与恢复可按下列步骤进行
一 备份
手动创建全量备份
执行命令生成包含仓库、数据库与上传文件的归档:
gitlab-rake gitlab:backup:creategitlab-backup create修改备份目录与保留策略
编辑 /etc/gitlab/gitlab.rb:
gitlab_rails['backup_path'] = "/opt/gitlab-backups"gitlab_rails['backup_keep_time'] = 2592000(单位:秒,示例为30天)gitlab-ctl reconfigure 使配置生效。定时自动备份(crontab)
示例:每天 02:00 执行备份
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:creategitlab-backup 命令,可替换为相应路径。备份清单(迁移/灾备强烈建议一并备份)
二 恢复
前置条件
gitlab-ctl reconfigure。chown git:root /var/opt/gitlab/backupschown git.git /var/opt/gitlab/backups/<备份文件>.tarchmod -R 755 /var/opt/gitlab/backups。执行恢复
gitlab-ctl stop unicorn、gitlab-ctl stop sidekiqgitlab-ctl stop puma、gitlab-ctl stop sidekiqgitlab-rake gitlab:backup:restore BACKUP=1700647561_2023_11_22_13_12_15gitlab-rake gitlab:backup:restore BACKUP=1700647561_2023_11_22_13_12_15_gitlab_backup.targitlab-ctl startgitlab-ctl reconfigure三 迁移场景要点
gitlab-ctl reconfigure 与重启。四 常见问题与最佳实践
backup_keep_time 做滚动保留。