极狐GitLab 如何在 helm 中恢复数据

本文作者:徐晓伟

GitLab 是一个全球知名的一体化 DevOps 平台,很多人都通过私有化部署 GitLab 来进行源代码托管。极狐GitLab 是 GitLab 在中国的发行版,专门为中国程序员服务。可以一键式部署极狐GitLab。

本文主要讲述了如何在极狐GitLab 恢复 GitLab 历史备份数据

文档

  1. 恢复 极狐GitLab 安装实例

本实例数据恢复

如果当前 极狐GitLab 实例数据被误删、实例异常,可通过历史备份进行数据恢复

记下数据库客户端的当前副本数,供后续重启使用

# -n gitlab-test:代表命名空间
# release=my-gitlab:代表 helm 安装 gitlab 时的名称
# -lapp=sidekiq:代表 sidekiq-all-in-1-v2 Deployment,默认 1 个副本
# -lapp=webservice:代表 webservice-default Deployment,默认 2 个副本
# -lapp=prometheus:代表 prometheus-server Deployment,默认 1 个副本
kubectl -n gitlab-test get deploy -lapp=sidekiq,release=my-gitlab -o jsonpath='{.items[].spec.replicas}{"\n"}'
kubectl -n gitlab-test get deploy -lapp=webservice,release=my-gitlab -o jsonpath='{.items[].spec.replicas}{"\n"}'
kubectl -n gitlab-test get deploy -lapp=prometheus,release=my-gitlab -o jsonpath='{.items[].spec.replicas}{"\n"}'

停止数据库的客户端,防止锁干扰恢复过程

kubectl -n gitlab-test scale deploy -lapp=sidekiq,release=my-gitlab --replicas=0
kubectl -n gitlab-test scale deploy -lapp=webservice,release=my-gitlab --replicas=0
kubectl -n gitlab-test scale deploy -lapp=prometheus,release=my-gitlab --replicas=0

查看 Toolbox pod

kubectl -n gitlab-test get pods -lrelease=my-gitlab,app=toolbox
# manual-backup-1-xxx:代表个人备份的 pod,无需关注
# my-gitlab-toolbox-backup-xxx-xxx:代表定时任务备份的 pod,无需关注
# my-gitlab-toolbox-xxx-xxx:代表 Toolbox pod 容器,需要记录此名称,用于后续使用
[root@anolis-7-9 ~]# kubectl -n gitlab-test get pods -lrelease=my-gitlab,app=toolbox
NAME                                      READY   STATUS      RESTARTS   AGE
manual-backup-1-9db78                     0/1     Completed   0          46h
my-gitlab-toolbox-5b7c4f8c6b-zccrv        1/1     Running     0          8m46s
my-gitlab-toolbox-backup-28393980-f9m8h   0/1     Completed   0          3h3m
[root@anolis-7-9 ~]# 

直接使用备份数据的 URL 链接恢复数据(推荐)

备份数据目录
[root@anolis-7-9 ~]# ll -h /gitlab-test/my-gitlab-minio-pv/gitlab-backups/
total 11M
-rw-rw-r-- 1 1000 1000 5.1M Dec 25 14:18 1703484999_2023_12_25_16.7.0-ee_gitlab_backup.tar
-rw-r--r-- 1 1000 1000 5.1M Dec 27 09:38 1703640824_2023_12_27_16.7.0-ee_gitlab_backup.tar
[root@anolis-7-9 ~]# 
使用 httpd 创建静态资源服务

使用其他方式创建静态资源服务也可以

docker run \--restart=always \-itd \--privileged=true \--name 2.4.48 \-p 180:80 \-v /gitlab-test/my-gitlab-minio-pv/gitlab-backups/:/usr/local/apache2/htdocs/ \-v /etc/localtime:/etc/localtime \-d httpd:2.4.48
查看静态资源
  • 访问 httpd

    httpd-1.png

使用静态资源 URL 恢复数据
kubectl -n gitlab-test exec my-gitlab-toolbox-5b7c4f8c6b-zccrv -it -- backup-utility --restore -f http://172.25.25.32:180/1703640824_2023_12_27_16.7.0-ee_gitlab_backup.tar

成功示例

[root@anolis-7-9 ~]# kubectl -n gitlab-test exec my-gitlab-toolbox-5b7c4f8c6b-zccrv -it -- backup-utility --restore -f http://172.25.25.32:180/1703640824_2023_12_27_16.7.0-ee_gitlab_backup.tar
Defaulted container "toolbox" out of: toolbox, certificates (init), configure (init)
Downloading from http://172.25.25.32:180/1703640824_2023_12_27_16.7.0-ee_gitlab_backup.tar
############################################################################################################################################################ 100.0%
Unpacking backup
2023-12-27 12:28:10 +0800 -- Restoring database ... 
2023-12-27 12:28:10 +0800 -- Be sure to stop Puma, Sidekiq, and any other process that
connects to the database before proceeding. For Omnibus
installs, see the following link for more information:
https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installationsBefore restoring the database, we will remove 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)? yes
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
2023-12-27 12:28:32 +0800 -- Cleaning the database ... 
2023-12-27 12:28:35 +0800 -- done
Restoring PostgreSQL database gitlabhq_production ... ERROR:  must be owner of extension pg_trgm
ERROR:  must be owner of extension btree_gist
ERROR:  must be owner of extension pg_trgm
SETset_config 
------------
...
[DONE]
Source backup for the database ci doesn't exist. Skipping the task
2023-12-27 12:28:53 +0800 -- Restoring database ... done
2023-12-27 12:28:53 +0800 -- Deleting backup and restore PID file ... done
2023-12-27 12:29:08 +0800 -- Restoring repositories ... 
{"command":"restore","gl_project_path":"xuxiaowei-com-cn.wiki","level":"info","msg":"started restore","pid":65,"relative_path":"@groups/19/58/19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7.wiki.git","storage_name":"default","time":"2023-12-27T04:29:08.837Z"}
...
2023-12-27 12:29:09 +0800 -- Restoring repositories ... done
2023-12-27 12:29:09 +0800 -- Deleting backup and restore PID file ... done
Restoring artifacts ...
done
Restoring packages ...
Restoring pages ...
[root@anolis-7-9 ~]# 
恢复副本数量
  • 使用上述命令记录的副本数进行副本恢复
kubectl -n gitlab-test scale deploy -lapp=sidekiq,release=my-gitlab --replicas=1
kubectl -n gitlab-test scale deploy -lapp=webservice,release=my-gitlab --replicas=2
kubectl -n gitlab-test scale deploy -lapp=prometheus,release=my-gitlab --replicas=1

复制备份数据到容器 Toolbox pod 内进行数据恢复(不推荐)

不推荐的原因:如果备份数据过大(例如:超过 10G),可能会存在没有复制完成的情况,导致无法解压备份数据,无法恢复

复制备份数据到容器 Toolbox pod 内
  1. 查看历史备份数据

    [root@anolis-7-9 ~]# ll -h /gitlab-test/my-gitlab-minio-pv/gitlab-backups/
    total 11M
    -rw-rw-r-- 1 1000 1000 5.1M Dec 25 14:18 1703484999_2023_12_25_16.7.0-ee_gitlab_backup.tar
    -rw-r--r-- 1 1000 1000 5.1M Dec 27 09:38 1703640824_2023_12_27_16.7.0-ee_gitlab_backup.tar
    [root@anolis-7-9 ~]# 
    
  2. 复制到容器 Toolbox pod 内的 /srv/gitlab/tmp/backups 目录

    [root@anolis-7-9 ~]# kubectl -n gitlab-test cp /gitlab-test/my-gitlab-minio-pv/gitlab-backups/1703640824_2023_12_27_16.7.0-ee_gitlab_backup.tar my-gitlab-toolbox-5b7c4f8c6b-zccrv:/srv/gitlab/tmp/backups
    Defaulted container "toolbox" out of: toolbox, certificates (init), configure (init)
    [root@anolis-7-9 ~]# 
    [root@anolis-7-9 ~]# kubectl -n gitlab-test exec -it my-gitlab-toolbox-5b7c4f8c6b-zccrv ls /srv/gitlab/tmp/backups
    kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
    Defaulted container "toolbox" out of: toolbox, certificates (init), configure (init)
    1703640824_2023_12_27_16.7.0-ee_gitlab_backup.tar  gitlab-shell
    [root@anolis-7-9 ~]#
    
恢复数据
  • 使用 容器内  /srv/gitlab/tmp/backups 目录下的部分文件名, 格式:<timestamp>_<version>

    kubectl -n gitlab-test exec my-gitlab-toolbox-5b7c4f8c6b-zccrv -it -- backup-utility --restore -t 1703640824_2023_12_27_16.7.0-ee
    
  • 也可以使用 file:///<path>  指定文件路径绝对路径

    kubectl -n gitlab-test exec my-gitlab-toolbox-5b7c4f8c6b-zccrv -it -- backup-utility --restore -t file:///home/git/1703640824_2023_12_27_16.7.0-ee_gitlab_backup.tar
    

成功示例

[root@anolis-7-9 ~]# kubectl -n gitlab-test exec my-gitlab-toolbox-5b7c4f8c6b-zccrv -it -- backup-utility --restore -t 1703640824_2023_12_27_16.7.0-ee
Unpacking backup
2023-12-27 12:38:22 +0800 -- Restoring database ... 
2023-12-27 12:38:22 +0800 -- Be sure to stop Puma, Sidekiq, and any other process that
connects to the database before proceeding. For Omnibus
installs, see the following link for more information:
https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installationsBefore restoring the database, we will remove 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)? yes
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
2023-12-27 12:41:21 +0800 -- Cleaning the database ... 
2023-12-27 12:41:23 +0800 -- done
Restoring PostgreSQL database gitlabhq_production ... ERROR:  must be owner of extension pg_trgm
ERROR:  must be owner of extension btree_gist
ERROR:  must be owner of extension pg_trgm
SETset_config 
------------
...
[DONE]
Source backup for the database ci doesn't exist. Skipping the task
2023-12-27 12:41:37 +0800 -- Restoring database ... done
2023-12-27 12:41:37 +0800 -- Deleting backup and restore PID file ... done
2023-12-27 12:41:52 +0800 -- Restoring repositories ... 
{"command":"restore","gl_project_path":"xuxiaowei-com-cn.wiki","level":"info","msg":"started restore","pid":236,"relative_path":"@groups/19/58/19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7.wiki.git","storage_name":"default","time":"2023-12-27T04:41:52.584Z"}
...
2023-12-27 12:41:53 +0800 -- Restoring repositories ... done
2023-12-27 12:41:53 +0800 -- Deleting backup and restore PID file ... done
Restoring artifacts ...
done
Restoring packages ...
Restoring pages ...
[root@anolis-7-9 ~]# 
恢复副本数量
  • 使用上述命令记录的副本数进行副本恢复
kubectl -n gitlab-test scale deploy -lapp=sidekiq,release=my-gitlab --replicas=1
kubectl -n gitlab-test scale deploy -lapp=webservice,release=my-gitlab --replicas=2
kubectl -n gitlab-test scale deploy -lapp=prometheus,release=my-gitlab --replicas=1

问题

自定义 toolbox Deployment hostAliases

问题
2023-12-27 11:48:42 +0800 -- Restoring repositories ... done
2023-12-27 11:48:42 +0800 -- Deleting backup and restore PID file ... done
Restoring artifacts ...
[Error] ERROR: [Errno -2] Name or service not known
ERROR: Connection Error: Error resolving a server hostname.
Please check the servers address specified in 'host_base', 'host_bucket', 'cloudfront_host', 'website_endpoint'sync existing of artifacts failed
command terminated with exit code 1
解决方案
kubectl -n gitlab-test edit deployments.apps my-gitlab-toolbox
      # 添加 MinIO 对象储存的 host 解析hostAliases:- hostnames:- minio.test.helm.xuxiaowei.cnip: 172.25.25.32

信任 MinIO 对象储存域名证书

问题
Restoring artifacts ...
[Error] ERROR: SSL certificate verification failure: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)sync existing of artifacts failed
command terminated with exit code 1
解决办法
kubectl -n gitlab-test edit deployments.apps my-gitlab-toolbox
      containers:# 不验证证书- args:- /bin/bash- -c- cp -v -r -L /etc/gitlab/.s3cfg $HOME/.s3cfg && echo "check_ssl_certificate=false" >> $HOME/.s3cfg && while sleep 3600; do :; done

号外号外!
极狐GitLab 正在推出DevSecOps 成熟度测评!链接:https://gitlab.cn/devsecops-assessment/ 测评非常全面并提供了可靠建议,即使不付费买产品,对自己想要落地 DevSecOps 的用户具有很高的参考意义!快来动手试试吧!

DevSecOps 成熟度评估.png

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/807478.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

查杀linux挖矿病毒 kswapd0

中毒现象 高cpu占用&#xff0c;使用top命令查看cpu使用率长时间50%以上&#xff0c;cpu占用异常的进程八成就是挖矿病毒进程 此病毒隐藏了自己&#xff0c;top命令无法查看到挖矿病毒进程&#xff0c;可通过sysdig命令找到隐藏进程 安装sysdig curl -s https://s3.amazonaw…

[CSS]样式属性+元素设置

哎呀&#xff0c;好多东西&#xff0c;根本记不住&#xff0c;更多的还是边用边记吧&#xff0c;这里的代码就当使用范例&#xff0c;但其实如果可以让gpt应该会更好&#xff0c;哎学吧&#xff0c;反正记得住当然更好 文本 属性名描述word-break单词换行。取值如下&#xff1…

[自研开源] MyData数据融合平台 诚邀试用

MyData &#xff0c;一个旨在简化 Web 应用之间数据对接的工具&#xff0c;提高日常工作效率&#xff0c;如其名“我的数据” 旨在让用户更好的掌控和管理数据。 v1.0 的目标是&#xff1a;针对多应用之间数据集成的场景&#xff0c;为开发人员提供更安全、更方便的对接集成方…

Elasticsearch8.x 设置密码

文章目录 一、环境说明二、使用elasticsearch-reset-password工具修改1、elasticsearch-reset-password工具位置2、设置密码 一、环境说明 elasticsearch版本&#xff1a;8.13.0 系统版本&#xff1a;Ubuntu 18.04.6 二、使用elasticsearch-reset-password工具修改 1、elast…

【Java程序员面试专栏 综合面试指南】5年资深程序员面试指南

基础知识对于5年内工作经验的同学考察相对比较多。包括编程语言、计算机网络、操作系统、设计模式、分布式知识、MySQL、Redis这种。其中随着年限的增长,基础知识考察的会越来越少,例如操作系统基本上只在学生阶段考察,计算机网络对于5年经验来说也考察的相对较少。5年以上对…

优化策略:企业海量文件传输事件处理(上)

在当今快速发展的商业环境中&#xff0c;企业的数据量正以前所未有的速度增长。这种增长不仅带来了机遇&#xff0c;也带来了挑战&#xff0c;特别是在文件传输任务的管理上。文件传输是企业日常运营中不可或缺的一部分&#xff0c;它涉及到大量的数据流动和信息交换。因此&…

0 idea搭建springboot项目

1 2 3 4 5 配置文件 application.yaml server:servlet:context-path: /app #项目名controller //注入到spring容器 Controller public class HelloController {GetMapping("hello")ResponseBodypublic String hello(){return "Hello,SpringBoot";} }启…

【MATLAB 预测算法教程】_1粒子群算法优化BP神经网络预测 - 教程和对应MATLAB代码

本文以MATLAB自带的脂肪数据集为例,将数据保存在EXCEL工作簿内,方便替换数据使用,以下介绍粒子群算法优化BP神经网络预测的MATLAB代码编写,主要流程包括1. 读取数据 2.划分训练集和测试集 3.归一化 4.确定BP神经网络的隐含层最优节点数量 5. 使用粒子群算法优化BP的神经网络…

[数据概念|数据技术]智能合约如何助力数据资产变现

“ 区块链上数据具有高可信度&#xff0c;智能合约将区块链变得更加智能化&#xff0c;以支持企业场景。” 之前鼹鼠哥已经发表了一篇文章&#xff0c;简单介绍了区块链&#xff0c;那么&#xff0c;智能合约又是什么呢&#xff1f;它又是如何助力数据资产变现的呢&#xff1f;…

Swagger转换成Excel文件

1、添加swagger解析依赖包&#xff1a; <dependency><groupId>io.swagger.parser.v3</groupId><artifactId>swagger-parser</artifactId><version>2.1.12</version></dependency>2、示例代码&#xff1a; package com.rlclou…

华为校招机试 - 相似图片分类(20240410)

题目描述 小明想要处理一批图片&#xff0c;将相似的图片分类。 他首先对图片的特征采样&#xff0c;得到图片之间的相似度&#xff0c;然后按照以下规则判断图片是否可以归为一类&#xff1a; 相似度 > 0 表示两张图片相似如果 A 和 B 相似&#xff0c;B 和 C 相似&…

基于spring boot的大学生体质测试管理系统

基于spring boot的大学生体质测试管理系统设计与实现 开发语言&#xff1a;Java 框架&#xff1a;springboot JDK版本&#xff1a;JDK1.8 服务器&#xff1a;tomcat7 数据库&#xff1a;mysql 5.7&#xff08;一定要5.7版本&#xff09; 数据库工具&#xff1a;Navicat11 …

新鲜出炉!这一套二手平台管理系统,太牛了,直接领取【带源码】

​今天给大家分享一套基于SpringbootVue的二手平台管理系统源码&#xff0c;在实际项目中可以直接复用。(免费提供&#xff0c;文末自取) 一、系统运行图&#xff08;设计报告和接口文档&#xff09; 1、登陆页面 2、后台页面 3、设计报告包含接口文档 二、系统搭建视频教程 …

基于RKNN的YOLOv5安卓Demo

1.简介 基于RKNPU2 SDK 1.6.0版的安卓YOLOv5演示应用程序&#xff0c;选择图片进行对象检测并显示识别结果。 GitHub源码地址&#xff1a;https://github.com/shiyinghan/rknn-android-yolov5 2.实现过程 参考RKNN官方库RKNN Model Zoo提供的YOLOv5对象检测demo&#xff0c…

SQL注入sqli_labs靶场第三题

?id1and 11 and 11和?id1and 11 and 11进行测试如果11页面显示正常和原页面一样&#xff0c;并且12页面报错或者页面部分数据显示不正常&#xff0c;那么可以确定此处为字符型注入。 根据报错信息判断为单引号带括号注入 联合查询&#xff1a; 猜解列名 ?id1) order by 3-…

Java毕业设计 基于springboot vue撸宠平台 宠物系统

Java毕业设计 基于springboot vue撸宠平台 宠物系统 springboot撸宠平台 宠物系统 功能介绍 首页 图片轮播 用户或商家注册 用户或商家登录 登录验证码 店铺信息 店铺详情 店铺投诉 宠物信息 宠物详情 预订 退订 搜索 收藏 点赞 踩 评论 个人中心 更新信息 我的收藏 在线客服…

提升法律文书起草效率:AlphaGPT 助力律师快速生成诉讼和仲裁文件

法律文书起草对于法律专业人士而言是一项基础而关键的任务。无论是民事、刑事还是行政诉讼&#xff0c;以及仲裁案件&#xff0c;精确的法律文书撰写对于案件的成功至关重要。然而&#xff0c;这一过程往往既耗时又复杂&#xff0c;尤其是在处理复杂的案情和面对当事人难以理解…

syncfusion-diagram:demo1如何实现

xmlns:syncfusion"http://schemas.syncfusion.com/wpf" xmlns:stencil"clr-namespace:Syncfusion.UI.Xaml.Diagram.Stencil;assemblySyncfusion.SfDiagram.WPF"当我们进入syncfusion的diagram中&#xff0c;可以看到&#xff0c;一个非常炫酷的例子 不仅实…

为什么要部署IP SSL证书?怎么申请?

我们需要知道什么是IP SSL证书。SSL&#xff0c;全称为Secure Sockets Layer&#xff0c;即安全套接层&#xff0c;是为网络通信提供安全及数据完整性的一种安全协议。而IP SSL证书就是基于SSL协议的一种证书&#xff0c;它能够为网站和用户的数据传输提供加密处理&#xff0c;…

对称加密学习

对称加密是一种加密技术&#xff0c;它使用相同的密钥进行数据的加密和解密操作。这种加密方法因其高效性和速度优势&#xff0c;在数据加密领域得到了广泛的应用。 下面是两篇文章&#xff1a; AES加密学习-CSDN博客 加密算法学习-CSDN博客 推荐关注加密专栏&#xff1a; …