Gitlab日常维护(三)之Gitlab的备份、迁移、升级
一、Gitlab的备份
使用Gitlab一键安装包安装Gitlab非常简单, 同样的备份恢复与迁移也非常简单. 使用一条命令即可创建完整的Gitlab备份
[root@gitlab ~]# gitlab-rake gitlab:backup:create
//比如使用以上命令会在/var/opt/gitlab/backups目录下创建一个名称类似为1481598919_gitlab_backup.tar的压缩包, 这个压缩包就是Gitlab整个的完整部分,
其中开头的1481598919是备份创建的日期。 /etc/gitlab/gitlab.rb 配置文件须备份
/var/opt/gitlab/nginx/conf nginx配置文件
/etc/postfix/main.cfpostfix 邮件配置备份
1、Gitlab备份目录
可以通过/etc/gitlab/gitlab.rb配置文件来修改默认存放备份文件的目录
[root@code-server ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/gitlab/backups" //gitlab备份目录
gitlab_rails['backup_archive_permissions'] = 0644 //生成的备份文件权限
gitlab_rails['backup_keep_time'] = 7776000 //备份保留天数为3个月(即90天,这里是7776000秒) [root@code-server ~]# mkdir -p /data/gitlab/backups
[root@code-server ~]# chown -R git.git /data/gitlab/backups
[root@code-server ~]# chmod -R 777 /data/gitlab/backups 如上设置了gitlab备份目录路径为/data/gitlab/backups,最后使用下面命令重载gitlab配置文件,是上述修改生效!
root@code-server ~]# gitlab-ctl reconfigure
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
/var/opt/gitlab/backups修改为你想存放备份的目录即可, 修改完成之后使用gitlab-ctl reconfigure命令重载配置文件即可.
2、Gitlab自动备份
编写备份脚本,结合crontab实施自动定时备份,比如每天0点、6点、12点、18点各备份一次
[root@code-server backups]# pwd
/data/gitlab/backups
[root@code-server backups]# vim gitlab_backup.sh
#!/bin/bash
/usr/bin/gitlab-rake gitlab:backup:create CRON=1 注意:环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出 [root@code-server backups]# crontab -l
0 0,6,12,18 * * * /bin/bash -x /data/gitlab/backups/gitlab_backup.sh > /dev/null 2>&1
现在我们公司实现每天凌晨2点进行一次自动备份:通过crontab使用备份命令实现
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
二、Gitlab恢复
GItlab只能还原到与备份文件相同的gitlab版本。
假设在上面gitlab备份之前创建了test项目,然后不小心误删了test项目,现在就进行gitlab恢复操作: 1)停止相关数据连接服务
[root@code-server backups]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@code-server backups]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 1s, normally up
[root@code-server backups]# gitlab-ctl status
run: gitaly: (pid 98087) 1883s; run: log: (pid 194202) 163003s
run: gitlab-monitor: (pid 98101) 1883s; run: log: (pid 194363) 163002s
run: gitlab-workhorse: (pid 98104) 1882s; run: log: (pid 194362) 163002s
run: logrotate: (pid 98117) 1882s; run: log: (pid 5793) 160832s
run: nginx: (pid 98123) 1881s; run: log: (pid 194359) 163002s
run: node-exporter: (pid 98167) 1881s; run: log: (pid 194360) 163002s
run: postgres-exporter: (pid 98173) 1881s; run: log: (pid 194204) 163003s
run: postgresql: (pid 98179) 1880s; run: log: (pid 194365) 163002s
run: prometheus: (pid 98187) 1880s; run: log: (pid 194364) 163002s
run: redis: (pid 98230) 1879s; run: log: (pid 194358) 163002s
run: redis-exporter: (pid 98234) 1879s; run: log: (pid 194208) 163003s
down: sidekiq: 8s, normally up; run: log: (pid 194437) 163001s
down: unicorn: 21s, normally up; run: log: (pid 194443) 163001s 2)现在通过之前的备份文件进行恢复(必须要备份文件放到备份路径下,这里备份路径我自定义的/data/gitlab/backups,默认的是/var/opt/gitlab/backups)
[root@code-server backups]# pwd
/data/gitlab/backups
[root@code-server backups]# ll
total 244
-rw-r--r-- 1 git git 245760 Nov 12 15:33 1510472027_2017_11_12_9.4.5_gitlab_backup.tar Gitlab的恢复操作会先将当前所有的数据清空,然后再根据备份数据进行恢复
[root@code-server backups]# gitlab-rake gitlab:backup:restore BACKUP=1510472027_2017_11_12_9.4.5
Unpacking backup ... done
Before restoring the database we recommend removing all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed. Do you want to continue (yes/no)?
........
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
WARNING: no privileges were granted for "public"
GRANT
[DONE]
done
Restoring repositories ...
* treesign/treesign ... [DONE]
* gateway/gateway ... [DONE]
* treesign/treesign-doc ... [DONE]
* qwsign/qwsign ... [DONE]
* qwsign/qwsign-doc ... [DONE]
* test/test ... [DONE]
Put GitLab hooks in repositories dirs [DONE]
done
Restoring uploads ...
done
Restoring builds ...
done
Restoring artifacts ...
done
Restoring pages ...
done
Restoring lfs objects ...
done
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
Do you want to continue (yes/no)? yes Deleting tmp directories ... done
done
done
done
done
done
done
done
[root@code-server backups]# 最后再次启动Gitlab
[root@code-server backups]# gitlab-ctl start
ok: run: gitaly: (pid 98087) 2138s
ok: run: gitlab-monitor: (pid 98101) 2138s
ok: run: gitlab-workhorse: (pid 98104) 2137s
ok: run: logrotate: (pid 98117) 2137s
ok: run: nginx: (pid 98123) 2136s
ok: run: node-exporter: (pid 98167) 2136s
ok: run: postgres-exporter: (pid 98173) 2136s
ok: run: postgresql: (pid 98179) 2135s
ok: run: prometheus: (pid 98187) 2135s
ok: run: redis: (pid 98230) 2134s
ok: run: redis-exporter: (pid 98234) 2134s
ok: run: sidekiq: (pid 104494) 0s
ok: run: unicorn: (pid 104497) 1s
[root@code-server backups]# gitlab-ctl status
run: gitaly: (pid 98087) 2142s; run: log: (pid 194202) 163262s
run: gitlab-monitor: (pid 98101) 2142s; run: log: (pid 194363) 163261s
run: gitlab-workhorse: (pid 98104) 2141s; run: log: (pid 194362) 163261s
run: logrotate: (pid 98117) 2141s; run: log: (pid 5793) 161091s
run: nginx: (pid 98123) 2140s; run: log: (pid 194359) 163261s
run: node-exporter: (pid 98167) 2140s; run: log: (pid 194360) 163261s
run: postgres-exporter: (pid 98173) 2140s; run: log: (pid 194204) 163262s
run: postgresql: (pid 98179) 2139s; run: log: (pid 194365) 163261s
run: prometheus: (pid 98187) 2139s; run: log: (pid 194364) 163261s
run: redis: (pid 98230) 2138s; run: log: (pid 194358) 163261s
run: redis-exporter: (pid 98234) 2138s; run: log: (pid 194208) 163262s
run: sidekiq: (pid 104494) 4s; run: log: (pid 194437) 163260s
run: unicorn: (pid 104497) 4s; run: log: (pid 194443) 163260s 恢复命令完成后,可以check检查一下恢复情况
[root@code-server backups]# gitlab-rake gitlab:check SANITIZE=true
Checking GitLab Shell ... GitLab Shell version >= 5.3.1 ? ... OK (5.3.1)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
5/1 ... ok
6/2 ... ok
5/3 ... repository is empty
12/4 ... ok
12/5 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK
Send ping to redis server: OK
gitlab-shell self-check successful Checking GitLab Shell ... Finished Checking Sidekiq ... Running? ... yes
Number of Sidekiq processes ... 1 Checking Sidekiq ... Finished Checking Reply by email ... Reply by email is disabled in config/gitlab.yml Checking Reply by email ... Finished Checking LDAP ... LDAP is disabled in config/gitlab.yml Checking LDAP ... Finished Checking GitLab ... Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ...
5/1 ... yes
6/2 ... yes
5/3 ... yes
12/4 ... yes
12/5 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.3 ? ... yes (2.3.3)
Git version >= 2.7.3 ? ... yes (2.13.4)
Active users: ... 11 Checking GitLab ... Finished 然后稍等一会(如果启动gitlab后,访问出现500,这是因为redis等程序还没完全启动,等一会儿访问就ok了),再次登录Gitlab,就会发现之前误删除的test项目已经恢复了! 另外:Gitlab迁移与恢复一样,但是要求两个GitLab版本号一致
三、Gitlab迁移
注意:新服务器的gitlab版本与旧的服务器相同。
迁移如同备份与恢复的步骤一样, 只需要将老服务器/var/opt/gitlab/backups目录下的备份文件拷贝到新服务器上的/var/opt/gitlab/backups即可(如果你没修改过默认备份目录的话).
但是需要注意的是:
新服务器上的Gitlab的版本必须与创建备份时的Gitlab版本号相同. 比如新服务器安装的是最新的7.60版本的Gitlab, 那么迁移之前, 最好将老服务器的Gitlab 升级为7.60在进行备份.
/etc/gitlab/gitlab.rb 这个gitlab配置文件须迁移,迁移后需要调整数据存放目录
/var/opt/gitlab/nginx/conf 这个nginx配置文件目录须迁移 /etc/gitlab/gitlab-secrets.json #复制新服务器相同的目录下
/etc/ssh/*key* #复制到新服务器相同目录下,解决ssh key认证不成功问题
[root@gitlab ~]# gitlab-ctl stop unicorn
[root@gitlab ~]# gitlab-ctl stop sidekiq
[root@gitlab ~]# chmod 777 /var/opt/gitlab/backups/1481598919_gitlab_backup.tar # 或 chown git:git /var/opt/gitlab/backups/1481598919_gitlab_backup.tar
[root@gitlab ~]# gitlab-rake gitlab:backup:restore BACKUP=1481598919
四、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-12.1.12-ce.0.el7.x86_64 或者上官网下载最新版本 gitlab对应软件包
gitlab官网地址: https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-12.1.12-ce.0.el7.x86_64.rpm
使用:
# rpm -Uvh gitlab-ce-12.1.12-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日常维护(三)之Gitlab的备份、迁移、升级的更多相关文章
- Git系列七之备份迁移 升级 恢复管理
0.Gitlab安装 1.安装和配置必要的依赖关系在CentOS7,下面的命令将在系统防火墙打开HTTP和SSH访问. yum install curl openssh-server postfix ...
- Gitlab 快速部署及日常维护 (二)
一.概述 上一篇我们将Gitlab的安装部署和初始化设置部分全部讲解完成了,接下来我们介绍Gitlab在日常工作中常遇见的问题进行梳理说明. 二.Gitlab的安装和维护过程中常见问题 1.Gitla ...
- GitLab → 搭建中常遇的问题与日常维护
开心一刻 隔壁有一个80多岁的老大爷,昨天在小区的一棵树下发现一条黑色的蛇,冻僵了,大爷善心大发,就把蛇揣在了怀里,想给它一点温暖. 今天一大早看到大爷在树上挂了一个牌子,写到:不准随地大小便! 搭建 ...
- Gitlab 快速部署及日常维护 (一)
一.GitLab简介GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务 二.GitLab系统架构git用户的主目录通常是/home/git(~ ...
- gitlab基本维护和使用
基本介绍 GitLab是一个自托管的Git项目仓库,可以自己搭建个人代码管理的仓库,功能与github类似. 安装 下载 gitlab下载地址: https://about.gitlab.com/do ...
- 第三篇——第二部分——第五文 配置SQL Server镜像——域环境SQL Server镜像日常维护
本文接上面两篇搭建镜像的文章: 第三篇--第二部分--第三文 配置SQL Server镜像--域环境:http://blog.csdn.net/dba_huangzj/article/details/ ...
- Centos下的GitLab的安装汉化和数据备份以及管理员密码重置
前言: 安装版本:gitlab-ce-8.8.5-ce.1.el7.x86_64.rpm 下载地址: https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yu ...
- Gitlab配置、备份、升级、迁移
0.Gitlab安装 1.安装和配置必要的依赖关系 在CentOS7,下面的命令将在系统防火墙打开HTTP和SSH访问. yum install curl openssh-server postfix ...
- Gitlab服务器维护
一. 内容 Gitlab服务器的更新 Gitlab服务器备份与恢复 导入Git仓库 二. Gitlab服务器的更新 1. 使用SSH登陆Gitlab服务器 2. 停止后端的unicorn服务器 [ro ...
随机推荐
- 攻防世界 - Misc(一)
base64÷4: 1.下载附件,是一个.txt文件,打开是一串字符, 666C61677B453333423746443841334238343143413936393945444442413234 ...
- 攻防世界—pwn—guess_num
题目分析 checksec检查文件保护机制 这个结果看的我满是问号??? \n ida分析程序 是一个猜数字的游戏,需要全部输入正确才能得到flag 根据大佬的wp得出一下内容 先使用srand()进 ...
- SAP ERP中权限参数和角色相关表
SAP版本:S/4 HANA 1809
- Java入门者:如何写出美观的Java代码?
前言 在帮助各位同学远程解决代码问题的时候,发现很多同学的代码都有一个共同问题:代码书写格式不规范.虽然代码书写规范对程序性能及运行并不影响,但影响着别人对你编程习惯或能力的第一印象,同时也会给阅读者 ...
- Description Resource Path Location Type Failure to transfer org.apache.maven.plugins:maven-surefire-
url:https://www.pianshen.com/article/8003307916/ Description Resource Path Location Type Failure to ...
- 词嵌入之GloVe
什么是GloVe GloVe(Global Vectors for Word Representation)是一个基于全局词频统计(count-based & overall statisti ...
- ECharts特效-折线图上一个光点来回移动
参考地址:https://www.makeapie.com/editor.html?c=xxxcG6NGk0 效果图打开上面的网址就可以看到. 核心代码如下,该效果实现的难点是数据的封装,还有eval ...
- CSS实现迷你键盘
最近做了一个迷你键盘的dome,这里分享给大家 dome下载地址(点击下载) 代码如下: <!DOCTYPE html> <html lang="en" > ...
- ././include/linux/kconfig.h:4:32: fatal error: generated/autoconf.h: No such file or directory 解决办法
我在编写内核驱动模块的时候报了一个非常奇怪的错误,如下图: 在目录下看了一下确实没有发现这个文件,感觉很奇怪,因为我记得之前编译模块是没有错误的,所以不可能是我代码写的有问题. 查阅了资料很多说要清除 ...
- Service Locator Pattern 服务定位
https://www.geeksforgeeks.org/service-locator-pattern/ Service Locator Pattern Last Updated: 06-03-2 ...