极狐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…

Ubuntu22.04虚拟环境安装CUDA10.1, CUDNN和pytorch

不同的神经网络有不同的配置&#xff0c;有些从前公开的github项目&#xff0c;一些包升级之后的版本缺少相关的函数&#xff0c;老版本又不兼容&#xff0c;只能在虚拟环境中重新安装环境。 首先理顺一下CUDA&#xff0c;CUDNN&#xff0c;cudatoolkit的关系。安装CUDA就是安…

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

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

CSP 比赛经验分享

中国软件专业技术资格&#xff08;水平&#xff09;考试&#xff08; CSP-S &#xff09;是一项旨在评价软件和信息技术 专业人员专业技术水平的考试。对于参加过 CSP 比赛的人来说&#xff0c;这是一个展示 自己编程能力、逻辑思维和解决问题能力的好机会。下面是一些基于…

选择成为一名程序员的原因

选择成为一名程序员的原因通常是一个综合考虑的结果,可能包括个人兴趣、职业发展前景以及其他因素。 1. 兴趣是主导因素 对编程和技术有着浓厚的兴趣是许多人选择这个职业的主要原因。编程需要逻辑思维、创造力和解决问题的能力,对于那些喜欢这种挑战并从中获得满足感的人来说…

ol.layer.Vector 的postrender和map的postrender事件有什么区别

ol.layer.Vector 的 postrender 事件和 ol.Map 的 postrender 事件在 OpenLayers 这个 JavaScript 库中都是事件&#xff0c;但它们针对的对象和触发的时机有所不同。 ol.layer.Vector 的 postrender 事件 ol.layer.Vector 的 postrender 事件是针对单个矢量图层&#xff08;…

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

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

ubuntu下使用ndk编译libevnet

libevent源码编译 源码的获取 http://www.ffmpeg.club/libevent.html 这是看夏老师课堂获取的&#xff0c;以后也要学他的课&#xff0c;所以就用整个源码编译&#xff0c;减少问题出现 编译静态库 https://blog.csdn.net/weixin_28927079/article/details/109380748 大概上是…

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";} }启…

【chatGPT】我:在Cadence Genus软件中,出现如下问题:......【3】

我 在Cadence Genus中&#xff0c;upf文件是什么&#xff0c;有什么作用 ChatGPT 在Cadence Genus中&#xff0c;UPF&#xff08;Unified Power Format&#xff09;文件是一个用于指导和描述设计的电源意图的标准文件格式。这个格式由Accellera制定&#xff0c;旨在提供一种方…

【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 …

nginx将一个路径下的多种url分别映射

背景 nginx如何将/static/下的images或script或css路径&#xff0c;分别映射到/data下的images、scripts或styles。 分析 可以在nginx的配置文件中添加以下配置&#xff0c;来实现url以/static/开头时&#xff0c;根据不同的子路径映射到不同的本地文件路径&#xff1a; loc…

Android app如何禁止运行在模拟器中

禁止 Android 应用程序在模拟器上运行涉及到在运行时检测应用是否在模拟器上运行&#xff0c;并根据情况做出相应的处理。以下是一种方法&#xff0c;通过判断设备的某些特征来检测模拟器&#xff1a; 创建一个用于检测模拟器的方法&#xff1a; public static boolean isEmu…