Gitlab备份与恢复、迁移与升级

  1. Gitlab安装,centos 7
    这里能够直接选择对应的rpm 包就行安装
https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

2.配置并启动node

gitlab-ctl reconfigure
gitlab-ctl status
gitlab-ctl stop
gitlab-ctl start

3.浏览到主机名和登陆Browse to the hostname and loginlinux

Username: root
Password: 5iveL!fenginx

1.Gitlab备份
使用Gitlab一键安装包安装Gitlab很是简单, 一样的备份恢复与迁移也很是简单. 使用一条命令便可建立完整的Gitlab备份:git

gitlab-rake gitlab:backup:create

使用以上命令会在/var/opt/gitlab/backups目录下建立一个名称相似为
1481598919_gitlab_backup.tar的压缩包, 这个压缩包就是Gitlab整个的完整部分, 其中开头的1481598919是备份建立的日期centos

/etc/gitlab/gitlab.rb 配置文件须备份 
/var/opt/gitlab/nginx/conf nginx配置文件 
/etc/postfix/main.cfpostfix 邮件配置备份

1.1Gitlab备份目录
能够经过/etc/gitlab/gitlab.rb配置文件来修改默认存放备份文件的目录ruby

gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
/var/opt/gitlab/backups修改成你想存放备份的目录便可, 修改完成以后使用gitlab-ctl reconfigure命令重载配置文件便可.

1.2Gitlab自动备份
实现天天凌晨2点进行一次自动备份:经过crontab使用备份命令实现bash

0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

2.Gitlab恢复
Gitlab的从备份恢复也很是简单:服务器

# 中止相关数据链接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# 从1481598919编号备份中恢复
gitlab-rake gitlab:backup:restore BACKUP=1481598919
启动Gitlab
sudo gitlab-ctl start

3.gitlab迁移
迁移如同备份与恢复的步骤同样, 只须要将老服务器curl

/var/opt/gitlab/backups

目录下的备份文件拷贝到新服务器上的/var/opt/gitlab/backups便可(若是你没修改过默认备份目录的话).
可是须要注意的是新服务器上的Gitlab的版本必须与建立备份时的Gitlab版本号相同. 好比新服务器安装的是最新的7.60版本的Gitlab, 那么迁移以前, 最好将老服务器的Gitlab 升级为7.60在进行备份.socket

/etc/gitlab/gitlab.rb gitlab配置文件须迁移,迁移后须要调整数据存放目录 
/var/opt/gitlab/nginx/conf nginx配置文件目录须迁移

[root@linux-node1 ~]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@linux-node1 ~]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
[root@linux-node1 ~]# chmod 777 /var/opt/gitlab/backups/1481598919_gitlab_backup.tar
[root@linux-node1 ~]# gitlab-rake gitlab:backup:restore BACKUP=1481598919

4.gitlab升级
1.关闭gitlab服务

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl stop nginx

2.备份gitlab

gitlab-rake gitlab:backup:create

3.下载gitlab的RPM包并进行升级

curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
yum update gitlab-ce

或者直接安装高版本
yum install gitlab-ce-8.12.13-ce.0.el7.x86_64
或者上官网下载最新版本 gitlab对应软件包 gitlab官网
使用 rpm -Uvh gitlab-ce-8.12.13-ce.0.el7.x86_64
报错.
Error executing action run on resource 'ruby_block[directory resource: /var/opt/gitlab/git-data/repositories]'
解决方法:
sudo chmod 2770 /var/opt/gitlab/git-data/repositories
4.启动并查看gitlab版本信息

gitlab-ctl reconfigure
gitlab-ctl restart
# head -1 /opt/gitlab/version-manifest.txt   
gitlab-ce 8.7.3

5.gitlab更改默认Nginx
更换gitlab自带Nginx,使用自行编译Nginx来管理gitlab服务。

编辑gitlab配置文件禁用自带Nignx服务器
```
vi /etc/gitlab/gitlab.rb
...

设置nginx为false,关闭自带Nginx

nginx['enable'] = false
...
检查默认nginx配置文件,并迁移至新Nginx服务

/var/opt/gitlab/nginx/conf/nginx.conf #nginx配置文件,包含gitlab-http.conf文件
/var/opt/gitlab/nginx/conf/gitlab-http.conf #gitlab核心nginx配置文件
重启 nginx、gitlab服务

$ sudo gitlab-ctl reconfigure
$ sudo service nginx restart
访问报502。缘由是nginx用户没法访问gitlab用户的socket文件。 重启gitlab须要从新受权

chmod -R o+x /var/opt/gitlab/gitlab-rails

相关文章
相关标签/搜索