概述
本文档主要备份恢复gitlab数据,仅限Omnibus安装 的gitlab
备份数据
# gitlab-rake gitlab:backup:create
上述命令会在/var/opt/gitlab/backups目录创建一个名称类似于1552845801_2019_03_18_10.7.3_gitlab_backup.tar的压缩包
注:可以通过修改配置文件/etc/gitlab/gitlab.rb配置文件如下参数修改备份文件存储位置
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
备份配置文件
直接将配置文件复制保存
- gitlab配置文件:/etc/gitlab/gitlab.rb nginx
- 配置文件:/var/opt/gitlab/nginx.conf
- postfix邮件配置:/etc/postfix/main.cf
定时备份
设置定时备份,并保留7天备份数据,该备份不会备份gitlab配置文件
使用root用户
sudo su -
crontab -e
设置每天凌晨两点创建备份
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
设置七天后自动删除备份
在配置文件中添加如下行 并重新配置:
# vi /etc/gitlab/gitlab.rb
gitlab_rails['backup_keep_time'] = 604800
重新加载配置
sudo gitlab-ctl reconfigure
恢复
将备份的文件复制到指定目录下
sudo cp 1552845801_2019_03_18_10.7.3_gitlab_backup.tar /var/opt/gitlab/backups/
停止连接到数据库的进程。让剩下的GitLab运行:
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
# Verify
sudo gitlab-ctl status
还原备份,指定要还原的备份的时间戳:
# This command will overwrite the contents of your GitLab database!
sudo gitlab-rake gitlab:backup:restore BACKUP=1552845801_2019_03_18_10.7.3
重启并检查GitLab:
sudo gitlab-ctl restart
sudo gitlab-rake gitlab:check SANITIZE=true