版本环境:html
[root@localhost gitlab]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [root@localhost gitlab]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION 8.15.4
先打开/etc/gitlab/gitlab.rb配置文件,查看一个和备份相关的配置项:git
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
该项定义了默认备份出文件的路径,能够经过修改该配置,并执行 gitlab-ctl reconfigure 或者 gitlab-ctl restart 重启服务生效。备份执行一条命令就搞定:/opt/gitlab/bin/gitlab-rake gitlab:backup:create ,也能够加到crontab中定时执行:数据库
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
能够到/var/opt/gitlab/backups找到备份包,解压查看,会发现备份的仍是比较全面的,数据库、repositories、build、upload等分类仍是比较清晰的。浏览器
天天执行备份,确定有目录被爆满的风险,咱们能够立马想到的能够经过find 查找必定的时间前的文件,配合rm进行删除。不过不须要这么麻烦,gitlab-ce自身集成的有自动删除配置。一样打开/etc/gitlab/gitlab.rb配置文件,能够找到以下配置:服务器
gitlab_rails['backup_keep_time'] = 604800
这里是设置备份保留7天(7*3600*24=604800),秒为单位,若是想增大或减少,能够直接在该处配置,并经过gitlab-ctl restart 重启服务生效。ide
备份完成,会在备份目录中生成一个当天日期的tar包。gitlab
1.安装gitlabui
安装包下载:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/spa
官网地址:http://www.shcsinfo.com/china/gitlabeedownload.htmlrest
上传到服务器,yum安装便可
yum -y localinstall gitlab-ce-8.15.4-ce.0.el7.x86_64.rpm
初始化,就执行一次
gitlab-ctl reconfigure
启动
gitlab-ctl status/stop/start
经过本机IP访问页面,设置初始密码,其余操做相似GitHUB。
2.恢复gitlab
恢复前须要先停掉数据链接服务:
gitlab-ctl stop unicorn gitlab-ctl stop sidekiq
若是是台空主机,没有任何操做,理论上不停这两个服务也能够。停这两个服务是为了保证数据一致性。若是你没修改过默认备份目录的话,将老服务器/var/opt/gitlab/backups目录下的备份文件拷贝到新服务器上的/var/opt/gitlab/backups
[root@localhost gitlab]# rsync -avz 1530773117_2018_07_05_gitlab_backup.tar 10.0.3.111:/var/opt/gitlab/backups/
600权限是无权恢复的。 --- 这里改为了777
[root@yunwei-test backups]# pwd
/var/opt/gitlab/backups [root@yunwei-test backups]# chmod 777 1530773117_2018_07_05_gitlab_backup.tar [root@yunwei-test backups]# ll total 17328900
-rwxrwxrwx 1 git git 17744793600 Jul 5 14:47 1530773117_2018_07_05_gitlab_backup.tar
执行下面的命令进行恢复:后面再输入两次yes就完成恢复了。
gitlab-rake gitlab:backup:restore BACKUP=1530773117_2018_07_05_gitlab_backup.tar
PS:根据版本不一样恢复时可能有点小区别
[root@localhost backups]# gitlab-rake gitlab:backup:restore BACKUP=1537974886_2018_09_26_10.8.7 或者 [root@localhost backups]# gitlab-rake gitlab:backup:restore BACKUP=1537974886
恢复完成后,启动刚刚的两个服务,或者重启全部服务,再打开浏览器进行访问,发现数据和以前的一致:
gitlab-ctl start unicorn gitlab-ctl start sidekiq 或 gitlab-ctl restart
注意:经过备份文件恢复gitlab必须保证两台主机的gitlab版本一致,不然会提示版本不匹配。
遇到的报错:数据量太大了,磁盘空间不足,打包报错。