gitlab 备份&恢复
发表于:2022-04-20 |
Gitlab 成功运行起来之后,最终的事情就是定期的备份,遇到问题后的还原。

备份配置
默认 Gitlab 的备份文件会创建在/var/opt/gitlab/backups文件夹中,格式为时间戳_日期_版本号_gitlab_backup.tar,例如:1515031353_2018_01_04_10.3.2_gitlab_backup.tar。
修改备份文件夹,需要修改配置文件/etc/gitlab/gitlab.rb中的:

gitlab_rails['backup_path'] = '/your_wish/backups'
然后gitlabctl-reconfigure生效。

手动备份
命令:gitlab-backup create

For GitLab 12.1 and earlier, use

gitlab-rake gitlab:backup:create
会在命令执行的时间点,在你配置的文件夹或者默认文件夹创建一个备份文件。

自动备份
0 2 * * * /opt/gitlab/bin/gitlab-backup create CRON=1
备份恢复
First make sure your backup tar file is in the backup directory described in the gitlab.rb configuration gitlab_rails['backup_path']. The default is /var/opt/gitlab/backups. It needs to be owned by the git user.

cp 11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar /var/opt/gitlab/backups/
chown git.git /var/opt/gitlab/backups/11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar
Stop the processes that are connected to the database. Leave the rest of GitLab running:

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# Verify
gitlab-ctl status
Next, restore the backup, specifying the timestamp of the backup you wish to restore:

# This command will overwrite the contents of your GitLab database!
gitlab-backup restore BACKUP=1493107454_2018_04_25_10.6.4-ce
For GitLab 12.1 and earlier, use

gitlab-rake gitlab:backup:restore
Next, restore /etc/gitlab/gitlab-secrets.json if necessary as mentioned above.

Reconfigure, restart and check GitLab:

gitlab-ctl reconfigure
gitlab-ctl restart
gitlab-rake gitlab:check SANITIZE=true
If there is a GitLab version mismatch between your backup tar file and the installed version of GitLab, the restore command will abort with an error. Install the correct GitLab version and try again.
上一篇:
docker 删除不用的镜像
下一篇:
解决:Docker下运行Mysql出现:mbind: Operation not permitted