关于gitlab数据丢失的问题

gitlab使用k8s 1.18.2部署,部署yaml文件如下:
1.gitlab-redis.yaml:

 apiVersion: v1
          kind: Namespace
          metadata:
             name: gitlab
             labels:
               name: gitlab
          ---
          apiVersion: v1
          kind: PersistentVolume
          metadata:
            name: gitlab-redis-pv
            namespace: gitlab
            labels:
              pv: gitlab-redis-pv
          spec:
            capacity:
              storage: 10Gi
            accessModes:
              - ReadWriteMany
            persistentVolumeReclaimPolicy: Retain
            storageClassName: nfs
            nfs:
              path: /opt/k8s/project-manage-sys/gitlab/redis
              server: k8s-nfs-server
          ---
          apiVersion: v1
          kind: PersistentVolumeClaim
          metadata:
            name: gitlab-redis-pvc
            namespace: gitlab
          spec:
            accessModes:
              - ReadWriteMany
            resources:
              requests:
                storage: 10Gi
            storageClassName: nfs
            selector:
              matchLabels:
                pv: gitlab-redis-pv
          ---   
          apiVersion: v1
          kind: ReplicationController
          metadata:
            name: redis
            namespace: gitlab
          spec:
            replicas: 1
            selector:
              name: redis
            template:
              metadata:
                name: redis
                labels:
                  name: redis
              spec:
                nodeSelector:
                  name: "k8s-node-1"
                containers:
                - name: redis
                  image: sameersbn/redis
                  env:
                  - name: TZ
                    value: Asia/Shanghai
                  ports:
                  - name: redis
                    containerPort: 6379
                  volumeMounts:
                  - mountPath: /var/lib/redis
                    name: data
                  livenessProbe:
                    exec:
                      command:
                      - redis-cli
                      - ping
                    initialDelaySeconds: 30
                    timeoutSeconds: 5
                  readinessProbe:
                    exec:
                      command:
                      - redis-cli
                      - ping
                    initialDelaySeconds: 5
                    timeoutSeconds: 1
                volumes:
                - name: data
                  persistentVolumeClaim:
                    claimName: gitlab-redis-pvc
          ---
          apiVersion: v1
          kind: Service
          metadata:
            name: redis
            namespace: gitlab
            labels:
              name: redis
          spec:
            ports:
              - name: redis
                port: 6379
                targetPort: redis
            selector:
              name: redis

2。gitlab-postgresql.yaml:

 apiVersion: v1
        kind: PersistentVolume
        metadata:
          name: gitlab-postgresql-pv
          namespace: gitlab
          labels:
            pv: gitlab-postgresql-pv
        spec:
          capacity:
            storage: 100Gi
          accessModes:
            - ReadWriteMany
          persistentVolumeReclaimPolicy: Retain
          storageClassName: nfs
          nfs:
            path: /opt/k8s/project-manage-sys/gitlab/postgresql
            server: k8s-nfs-server
        ---
        apiVersion: v1
        kind: PersistentVolumeClaim
        metadata:
          name: gitlab-postgresql-pvc
          namespace: gitlab
        spec:
          accessModes:
            - ReadWriteMany
          resources:
            requests:
              storage: 100Gi
          storageClassName: nfs
          selector:
            matchLabels:
              pv: gitlab-postgresql-pv
        ---
        apiVersion: v1
        kind: ReplicationController
        metadata:
          name: postgresql
          namespace: gitlab
        spec:
          replicas: 1
          selector:
            name: postgresql
          template:
            metadata:
              name: postgresql
              labels:
                name: postgresql
            spec:
              nodeSelector:
                name: "k8s-node-1"
              containers:
              - name: postgresql
                image: sameersbn/postgresql:10
                env:
                - name: TZ
                  value: Asia/Shanghai
                - name: DB_USER
                  value: gitlab
                - name: DB_PASS
                  value: passw0rd
                - name: DB_NAME
                  value: gitlab_production
                - name: DB_EXTENSION
                  value: pg_trgm
                ports:
                - name: postgres
                  containerPort: 5432
                volumeMounts:
                - mountPath: /var/lib/postgresql
                  name: data
        #        livenessProbe:
        #          exec:
        #            command:
        #            - pg_isready
        #            - -h
        #            - localhost
        #            - -U
        #            - postgres
        #          initialDelaySeconds: 30
        #          timeoutSeconds: 5
        #        readinessProbe:
        #          exec:
        #            command:
        #            - pg_isready
        #            - -h
        #            - localhost
        #            - -U
        #            - postgres
        #          initialDelaySeconds: 5
        #          timeoutSeconds: 1
              volumes:
              - name: data
                persistentVolumeClaim:
                  claimName: gitlab-postgresql-pvc
        ---
        apiVersion: v1
        kind: Service
        metadata:
          name: postgresql
          namespace: gitlab
          labels:
            name: postgresql
        spec:
          ports:
            - name: postgres
              port: 5432
              targetPort: postgres
          selector:
            name: postgresql

3.gitlab.yaml:

  apiVersion: v1
        kind: PersistentVolume
        metadata:
          name: gitlab-pv
          namespace: gitlab
          labels:
            pv: gitlab-pv
        spec:
          capacity:
            storage: 500Gi
          accessModes:
            - ReadWriteMany
          persistentVolumeReclaimPolicy: Retain
          storageClassName: nfs
          nfs:
            path: /opt/k8s/project-manage-sys/gitlab/gitlab
            server: k8s-nfs-server
        ---
        apiVersion: v1
        kind: PersistentVolumeClaim
        metadata:
          name: gitlab-pvc
          namespace: gitlab
        spec:
          accessModes:
            - ReadWriteMany
          resources:
            requests:
              storage: 500Gi
          storageClassName: nfs
          selector:
            matchLabels:
              pv: gitlab-pv
        ---
        apiVersion: v1
        kind: ReplicationController
        metadata:
          name: gitlab-ldap
          namespace: gitlab
        spec:
          replicas: 1
          selector:
            name: gitlab
          template:
            metadata:
              name: gitlab
              labels:
                name: gitlab
            spec:
              nodeSelector:
                name: "k8s-node-1"
              containers:
              - name: gitlab
                image: sameersbn/gitlab:12.1.6
                env:
                - name: TZ
                  value: Asia/Shanghai
                - name: GITLAB_TIMEZONE
                  value: Beijing
        
                - name: GITLAB_SECRETS_DB_KEY_BASE
                  value: long-and-random-alpha-numeric-string
                - name: GITLAB_SECRETS_SECRET_KEY_BASE
                  value: long-and-random-alpha-numeric-string
                - name: GITLAB_SECRETS_OTP_KEY_BASE
                  value: long-and-random-alpha-numeric-string
        
                - name: GITLAB_ROOT_PASSWORD
                  value: gitlab123
        
                - name: GITLAB_HOST
                  value: "10.7.11.115"
                - name: GITLAB_PORT
                  value: "30001"
                - name: GITLAB_SSH_PORT
                  value: "30002"
        
                - name: GITLAB_NOTIFY_ON_BROKEN_BUILDS
                  value: "true"
                - name: GITLAB_NOTIFY_PUSHER
                  value: "false"
        
                - name: GITLAB_BACKUP_SCHEDULE
                  value: daily
                - name: GITLAB_BACKUP_TIME
                  value: 01:00
        
                - name: DB_TYPE
                  value: postgres
                - name: DB_HOST
                  value: postgresql
                - name: DB_PORT
                  value: "5432"
                - name: DB_USER
                  value: gitlab
                - name: DB_PASS
                  value: passw0rd
                - name: DB_NAME
                  value: gitlab_production
        
                - name: REDIS_HOST
                  value: redis
                - name: REDIS_PORT
                  value: "6379"
                
                ports:
                - name: http
                  containerPort: 80
                - name: ssh
                  containerPort: 22
                volumeMounts:
                - mountPath: /home/git/data
                  name: data
                # livenessProbe:
                  # httpGet:
                    # path: /
                    # port: 80
                  # initialDelaySeconds: 180
                  # timeoutSeconds: 5
                # readinessProbe:
                  # httpGet:
                    # path: /
                    # port: 80
                  # initialDelaySeconds: 5
                  # timeoutSeconds: 1
              volumes:
              - name: data
                persistentVolumeClaim:
                  claimName: gitlab-pvc
        ---
        apiVersion: v1
        kind: Service
        metadata:
          name: gitlab
          namespace: gitlab
          labels:
            name: gitlab
        spec:
          type: ClusterIP
          ports:
            - name: http
              port: 80
              targetPort: http
            - name: ssh
              port: 22
              targetPort: ssh
          selector:
            name: gitlab
        ---
        kind: Service
        apiVersion: v1
        metadata:
          labels:
            name: gitlab
            type: LoadBalancer
          name: gitlab-balancer
          namespace: gitlab
        spec:
          ports:
          - name: http
            port: 80
            protocol: TCP
            targetPort: 80
            nodePort: 30001
          - name: ssh
            port: 22
            protocol: TCP
            targetPort: 22
            nodePort: 30002
          selector:
            name: gitlab
          type: NodePort
        ---
        # apiVersion: extensions/v1beta1
        # kind: Ingress
        # metadata:
          # name: gitlab
          # namespace: gitlab
          # annotations:
            # kubernetes.io/ingress.class: traefik
        # spec:
          # rules:
          # - host: gitlab.xxx.net
            # http:
              # paths:
              # - backend:
                  # serviceName: gitlab
                  # servicePort: 80

前两天因服务器断电,发现数据库中的数据部分丢失,仓库的数据可能还在,在5月底做了数据的全量备份,即nfs 目录:/opt/k8s/project-manage-sys/gitlab/gitlab 下的所有文件做了备份,到服务器断电前正常使用,请教有办法恢复吗?

摘要

此文本将被隐藏

你好,

  1. 请问现在的服务状态如何?除了丢失的数据以外,GitLab整体功能是否可以正常使用?
  2. 关于数据库中的数据部分丢失,请问大概是丢失了哪些数据?首先需要确认下丢失数据的范围,再评估是否可以通过其他方式找回。
  3. 关于数据的全量备份,请问你是如何备份的?备份的结果文件中,是否包含了数据库导出文件? 需要确认下DB、Repo、其他资源对象等的备份情况。
  4. 假设上述备份可用,你是希望恢复到5月底的时间节点吗?

您好:
1.目前gitlab可正常使用,但是数据库中的信息丢了一部分,通过gitlab登录看到的项目信息丢了一部分。
2.丢了项目、群组、用户等的信息,约1年多的项目信息。
3.文中提到的关于gitlab映射出的目录:/home/git/data,postgresql下的目录:/var/lib/postgresql ,所涉及的文件已备份。
4.如果可以的话,恢复到最近的数据。

1、使用5月底的备份数据,恢复仓库+数据库的数据到那个时间点,可行性还是比较大的。
2、5月底到断电期间:数据库数据,应该是恢复不了,仓库数据是否可以恢复,还需要看具体情况。