设为首页 收藏本站
查看: 781|回复: 0

[经验分享] Gitlab备份和恢复操作记录

[复制链接]

尚未签到

发表于 2018-1-11 09:29:50 | 显示全部楼层 |阅读模式
GItlab只能还原到与备份文件相同的gitlab版本。  
假设在上面gitlab备份之前创建了test项目,然后不小心误删了test项目,现在就进行gitlab恢复操作:
  
1)停止相关数据连接服务
  
[iyunv@code-server backups]# gitlab-ctl stop unicorn
  
ok: down: unicorn: 0s, normally up
  
[iyunv@code-server backups]# gitlab-ctl stop sidekiq
  
ok: down: sidekiq: 1s, normally up
  
[iyunv@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)现在通过之前的备份文件进行恢复
  
[iyunv@code-server backups]# pwd
  
/data/gitlab/backups
  
[iyunv@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的恢复操作会先将当前所有的数据清空,然后再根据备份数据进行恢复
  
[iyunv@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
  
[iyunv@code-server backups]#
  
最后再次启动Gitlab
  
[iyunv@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
  
[iyunv@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检查一下恢复情况
  
[iyunv@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版本号一致

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-433803-1-1.html 上篇帖子: gitlab docker安装配置ldap 下篇帖子: 基于GitLab的前端Assets发布体系
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表