注意事项:
一、部署gitlab版本需要与旧版本一致,否则在导入备份的时候报错
-
安装rpm
rpm -ivh ./gitlab-ce-11.2.3-ce.0.sles42.x86_64.rpm -
修改配置文件:
[root@gitlab mnt]# grep -v -E ‘#|$’ /etc/gitlab/gitlab.rb
external_url ‘http://10.19.0.207’ ##clone域名,可以是外网地址
gitlab_rails[‘manage_backup_path’] = true ##开启备份
gitlab_rails[‘backup_path’] = “/mnt/gitlab/backups” ##备份路径
git_data_dirs({
“default” => {
“path” => “/mnt/git-data” ##数据路径
}
}) -
初始化
gitlab-ctl reconfigure -
启动gitlab
gitlab-ctl restart
二、备份 + 导入
1)备份数据 会备份到配置文件中设置的备份目录中
gitlab-rake gitlab:backup:create RAILS_ENV=production
例如:
1661220380_2022_08_23_11.2.3_gitlab_backup.tar
2)导入数据(先拷贝至新服务中)
停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
2-1)拷贝数据至新服务器中,略
2-2)授权chown -R git.git /mnt/gitlab/backups/
2-3)导入数据
gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1661220380_2022_08_23_11.2.3 (注意这里没有后缀_gitlab_backup.tar)
###备份详解
设置定时任务(crontab -e)
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
重启crontab
systemctl restart crond
设置备份的天数
编辑/etc/gitlab/gitlab.rb文件。
###! The duration in seconds to keep backups before they are allowed to be deleted
keep 2 days
gitlab_rails[‘backup_keep_time’] = 172800
恢复备份的数据
停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
从1628100892_2021_08_05_12.1.1_gitlab_backup.tar 备份中恢复
gitlab-rake gitlab:backup:restore BACKUP=1628100892_2021_08_05_12.1.1
启动Gitlab
gitlab-ctl start