转载:Gitlab备份和恢复操作记录
转载:Gitlab备份和恢复操作记录
包含了备份和数据恢复的操作记录,实验可行
前面已经介绍了Gitlab环境部署记录,这里简单说下Gitlab的备份和恢复操作记录:
1)Gitlab的备份目录路径设置
|
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@code-server ~]# vim /etc/gitlab/gitlab.rbgitlab_rails['manage_backup_path'] = truegitlab_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 |
2)GItlab备份操作(使用备份命令"gitlab-rake gitlab:backup:create")
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
手动备份gitlab[root@code-server backups]# gitlab-rake gitlab:backup:createDumping database ...Dumping PostgreSQL database gitlabhq_production ... [DONE]doneDumping repositories ... * treesign/treesign ... [DONE] * gateway/gateway ... [DONE] * treesign/treesign-doc ... [SKIPPED] * qwsign/qwsign ... [DONE] * qwsign/qwsign-doc ... [DONE] * test/test ... [DONE]doneDumping uploads ...doneDumping builds ...doneDumping artifacts ...doneDumping pages ...doneDumping lfs objects ...doneDumping container registry images ...[DISABLED]Creating backup archive: 1510471890_2017_11_12_9.4.5_gitlab_backup.tar ... doneUploading backup archive to remote storage ... skippedDeleting tmp directories ... donedonedonedonedonedonedonedoneDeleting old backups ... done. (0 removed)然后查看下备份文件(文件权限是设定好的644)[root@code-server backups]# lltotal 244-rw-r--r-- 1 git git 245760 Nov 12 15:33 1510472027_2017_11_12_9.4.5_gitlab_backup.tar编写备份脚本,结合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 -l0 0,6,12,18 * * * /bin/bash -x /data/gitlab/backups/gitlab_backup.sh > /dev/null 2>&1 |
3)Gitlab自动备份
1).周期性计划任务
添加备份信息
$crontab -e
0 0 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
重启备份服务
$service crond restart
每天凌晨备份gitlab的数据
2).删除过期的备份文件
因为每天都会进行一次备份,而备份的数据比较大,磁盘空间会被大量使用,因此,定期删除过期的文件
$vim /var/opt/gitlab/backups/remove.sh
添加下面的内容
!/bin/bash
find "/var/opt/gitlab/backups/" -name ".tar" -ctime +1 -type f -exec rm -rf {} ;
设置每天晚上11点,删除两天前的备份
$contab -e
0 23 * * root /var/opt/gitlab/backups/remove.sh -D 2 #添加内容
赋予脚本执行权限,否则用户不能执行此脚本.
$chmod +x remove.sh
重启备份器
$service crond restart
4)Gitlab恢复操作
GItlab只能还原到与备份文件相同的gitlab版本。

|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
假设在上面gitlab备份之前创建了test项目,然后不小心误删了test项目,现在就进行gitlab恢复操作: 1)停止相关数据连接服务[root@code-server backups]# gitlab-ctl stop unicornok: down: unicorn: 0s, normally up[root@code-server backups]# gitlab-ctl stop sidekiqok: down: sidekiq: 1s, normally up[root@code-server backups]# gitlab-ctl statusrun: gitaly: (pid 98087) 1883s; run: log: (pid 194202) 163003srun: gitlab-monitor: (pid 98101) 1883s; run: log: (pid 194363) 163002srun: gitlab-workhorse: (pid 98104) 1882s; run: log: (pid 194362) 163002srun: logrotate: (pid 98117) 1882s; run: log: (pid 5793) 160832srun: nginx: (pid 98123) 1881s; run: log: (pid 194359) 163002srun: node-exporter: (pid 98167) 1881s; run: log: (pid 194360) 163002srun: postgres-exporter: (pid 98173) 1881s; run: log: (pid 194204) 163003srun: postgresql: (pid 98179) 1880s; run: log: (pid 194365) 163002srun: prometheus: (pid 98187) 1880s; run: log: (pid 194364) 163002srun: redis: (pid 98230) 1879s; run: log: (pid 194358) 163002srun: redis-exporter: (pid 98234) 1879s; run: log: (pid 194208) 163003sdown: sidekiq: 8s, normally up; run: log: (pid 194437) 163001sdown: unicorn: 21s, normally up; run: log: (pid 194443) 163001s 2)现在通过之前的备份文件进行恢复[root@code-server backups]# pwd/data/gitlab/backups[root@code-server backups]# lltotal 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.5Unpacking backup ... doneBefore restoring the database we recommend removing all existingtables to avoid future upgrade problems. Be aware that if you havecustom tables in the GitLab database these tables and all data will beremoved. Do you want to continue (yes/no)?........ALTER TABLEALTER TABLEALTER TABLEALTER TABLEWARNING: no privileges were granted for "public"GRANT[DONE]doneRestoring 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]doneRestoring uploads ...doneRestoring builds ...doneRestoring artifacts ...doneRestoring pages ...doneRestoring lfs objects ...doneThis 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 ... donedonedonedonedonedonedonedone[root@code-server backups]# 最后再次启动Gitlab[root@code-server backups]# gitlab-ctl startok: run: gitaly: (pid 98087) 2138sok: run: gitlab-monitor: (pid 98101) 2138sok: run: gitlab-workhorse: (pid 98104) 2137sok: run: logrotate: (pid 98117) 2137sok: run: nginx: (pid 98123) 2136sok: run: node-exporter: (pid 98167) 2136sok: run: postgres-exporter: (pid 98173) 2136sok: run: postgresql: (pid 98179) 2135sok: run: prometheus: (pid 98187) 2135sok: run: redis: (pid 98230) 2134sok: run: redis-exporter: (pid 98234) 2134sok: run: sidekiq: (pid 104494) 0sok: run: unicorn: (pid 104497) 1s[root@code-server backups]# gitlab-ctl statusrun: gitaly: (pid 98087) 2142s; run: log: (pid 194202) 163262srun: gitlab-monitor: (pid 98101) 2142s; run: log: (pid 194363) 163261srun: gitlab-workhorse: (pid 98104) 2141s; run: log: (pid 194362) 163261srun: logrotate: (pid 98117) 2141s; run: log: (pid 5793) 161091srun: nginx: (pid 98123) 2140s; run: log: (pid 194359) 163261srun: node-exporter: (pid 98167) 2140s; run: log: (pid 194360) 163261srun: postgres-exporter: (pid 98173) 2140s; run: log: (pid 194204) 163262srun: postgresql: (pid 98179) 2139s; run: log: (pid 194365) 163261srun: prometheus: (pid 98187) 2139s; run: log: (pid 194364) 163261srun: redis: (pid 98230) 2138s; run: log: (pid 194358) 163261srun: redis-exporter: (pid 98234) 2138s; run: log: (pid 194208) 163262srun: sidekiq: (pid 104494) 4s; run: log: (pid 194437) 163260srun: unicorn: (pid 104497) 4s; run: log: (pid 194443) 163260s恢复命令完成后,可以check检查一下恢复情况[root@code-server backups]# gitlab-rake gitlab:check SANITIZE=trueChecking GitLab Shell ...GitLab Shell version >= 5.3.1 ? ... OK (5.3.1)Repo base directory exists?default... yesRepo storage directories are symlinks?default... noRepo paths owned by git:root, or git:git?default... yesRepo paths access is drwxrws---?default... yeshooks directories in repos are links: ...5/1 ... ok6/2 ... ok5/3 ... repository is empty12/4 ... ok12/5 ... okRunning /opt/gitlab/embedded/service/gitlab-shell/bin/checkCheck GitLab API access: OKAccess to /var/opt/gitlab/.ssh/authorized_keys: OKSend ping to redis server: OKgitlab-shell self-check successfulChecking GitLab Shell ... FinishedChecking Sidekiq ...Running? ... yesNumber of Sidekiq processes ... 1Checking Sidekiq ... FinishedChecking Reply by email ...Reply by email is disabled in config/gitlab.ymlChecking Reply by email ... FinishedChecking LDAP ...LDAP is disabled in config/gitlab.ymlChecking LDAP ... FinishedChecking GitLab ...Git configured correctly? ... yesDatabase config exists? ... yesAll migrations up? ... yesDatabase contains orphaned GroupMembers? ... noGitLab config exists? ... yesGitLab config up to date? ... yesLog directory writable? ... yesTmp directory writable? ... yesUploads directory exists? ... yesUploads directory has correct permissions? ... yesUploads directory tmp has correct permissions? ... yesInit 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 ... yes6/2 ... yes5/3 ... yes12/4 ... yes12/5 ... yesRedis version >= 2.8.0? ... yesRuby version >= 2.3.3 ? ... yes (2.3.3)Git version >= 2.7.3 ? ... yes (2.13.4)Active users: ... 11Checking GitLab ... Finished 然后稍等一会(如果启动gitlab后,访问出现500,这是因为redis等程序还没完全启动,等一会儿访问就ok了),再次登录Gitlab,就会发现之前误删除的test项目已经恢复了! 另外:Gitlab迁移与恢复一样,但是要求两个GitLab版本号一致 |
赋予脚本执行权限,否则用户不能执行此脚本.
$chmod +x remove.sh
转载:Gitlab备份和恢复操作记录的更多相关文章
- Gitlab备份和恢复操作记录
前面已经介绍了Gitlab环境部署记录,这里简单说下Gitlab的备份和恢复操作记录: 1)Gitlab的备份目录路径设置 [root@code-server ~]# vim /etc/gitlab/ ...
- Gitlab备份和恢复操作
参考:https://www.cnblogs.com/kevingrace/p/7821529.html 一,设置开启备份以及备份路径 /etc/gitlab/gitlab.rb gitlab_rai ...
- gitlab备份、恢复、升级
1.备份 gitlab的备份很简单,只要使用命令: gitlab-rake gitlab:backup:create 即可将当前的数据库.代码全部备份到/var/opt/gitlab/backups ...
- gitlab备份及恢复
gitlab备份步骤 https://blog.csdn.net/qq_31666147/article/details/79844107 gitlab版本 下载地址 https://mirrors ...
- Gitlab+Jenkins学习之路(四)之gitlab备份和恢复
gitlab的备份和恢复 (1)创建备份目录,并授权 [root@linux-node1 ~]# mkdir /data/backups/gitlab -p [root@linux-node1 ~]# ...
- gitlab 备份和恢复
前言 gitlab这个代码托管工具真是强大,很多东西都是做好了直接用的. 这里就包括备份和恢复功能. 正文 备份 我们可以直接运行此命令,来进行备份. sudo gitlab-rake gitlab: ...
- Gitlab备份以及恢复
1.迁移准备工作和思路 从a服务器迁移到b服务器,由于Gitlab自身的兼容性问题,高版本的Gitlab无法恢复低版本备份的数据,需要注意在b服务器部署和a服务器一样版本的gitlab,部署好环境后开 ...
- Gitlab 备份迁移恢复报错gtar: .: Cannot mkdir: No such file or directory
1. 版本信息 OS: centos 6.9 Gitlab: gitlab-ce.10.7.4 gitlab-ce.10.8.0 gitlab-ce.10.8.3 gitlab-ce.10.8.4 2 ...
- gitlab备份和恢复
备份 生产环境下,备份是必需的.需要备份的文件有:配置文件和数据文件. 备份配置文件 配置文件包含密码等敏感信息,不要和数据文件放在一起. sh -c 'umask 0077; tar -cf $(d ...
随机推荐
- zabbix3.0.4报错Get value from agent failed: cannot connect to [[1.1.1.1]:10050]: [4] Interrupted syste
一.问题描述 部署完Zabbix agent之后,Server无法获取到数据.报错.报错信息如下: Get value from agent failed: cannot connect to [[1 ...
- CCF2014123集合竞价(C语言版)
问题描述 某股票交易所请你编写一个程序,根据开盘前客户提交的订单来确定某特定股票的开盘价和开盘成交量. 该程序的输入由很多行构成,每一行为一条记录,记录可能有以下几种: 1. buy p s 表示一个 ...
- LeetCode(45): 跳跃游戏 II
Hard! 题目描述: 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 你的目标是使用最少的跳跃次数到达数组的最后一个位置. 示例: 输入: [ ...
- poj3696 欧拉函数引用
不知道错在哪里,永远T /* 引理:a,n互质,则满足a^x=1(mod n)的最小正整数x0是φ(n)的约数 思路:求出d=gcd(L,8) 求出φ(9L/d)的约数集合,再枚举约数x,是否满足10 ...
- poj3728 倍增法lca 好题!
lca的好题!网上用st表和离线解的比较多,用树上倍增也是可以做的 不知道错在哪里,等刷完了这个专题再回来看 题解链接https://blog.csdn.net/Sd_Invol/article/de ...
- python 全栈开发,Day21(抽象类,接口类,多态,鸭子类型)
一.昨日复习 派生方法和派生属性 super 只有在子父类拥有同名方法的时候, 想使用子类的对象调用父类的方法时,才使用super super在类内 : super().方法名(arg1,..) 指名 ...
- javafx基于使用fxml布局的tableview数据绑定用法
来个简单明了的 fxml的tableview数据绑定和java代码方式的数据绑定很像,不同的在于要有一到映射 首先看个目录 1.界面文件Sample.fxml <?xml version=&qu ...
- JS高级 - 面向对象1(this,Object ,工厂方式,new )
面向对象三要素: 封装 继承 多态 1.this 详解,事件处理中this的本质 window this -- 函数属于谁 <script type="text/javascript& ...
- 这篇文章讲得精彩-深入理解 Python 异步编程(上)!
可惜,二和三现在还没有出来~ ~~~~~~~~~~~~~~~~~~~~~~~~~ http://python.jobbole.com/88291/ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
- [转] Optimizely:在线网站A/B测试平台
Optimizely:在线网站A/B测试平台是一家提供 A/B 测试服务的公司.A/B 测试能够对比不同版本的设计,选取更吸引用户眼球的那一款,从而带来更为优化的个人体验.让网站所有者易于对不同版本的 ...