15.4. 가상 머신 복원

Restore CR 을 생성하여 OADP(OpenShift API for Data Protection) Backup CR(사용자 정의 리소스)을복원합니다.

애플리케이션 컨테이너가 시작되기 전에 또는 애플리케이션 컨테이너 자체에서 init 컨테이너에서 명령을 실행하려면 Restore CR에 후크 를 추가할 수 있습니다.

15.4.1. Restore CR 생성

Restore CR을 생성하여 Backup CR(사용자 정의 리소스)을 복원합니다.

사전 요구 사항

  • OADP(OpenShift API for Data Protection) Operator를 설치해야 합니다.
  • DataProtectionApplication CR은 Ready 상태여야 합니다.
  • Velero Backup CR이 있어야 합니다.
  • PV(영구 볼륨) 용량이 백업 시 요청된 크기와 일치해야 합니다. 필요한 경우 요청된 크기를 조정합니다.

절차

  1. 다음 예와 같이 Restore CR을 생성합니다.

    apiVersion: velero.io/v1
    kind: Restore
    metadata:
      name: <restore>
      namespace: openshift-adp
    spec:
      backupName: <backup> 1
      includedResources: [] 2
      excludedResources:
      - nodes
      - events
      - events.events.k8s.io
      - backups.velero.io
      - restores.velero.io
      - resticrepositories.velero.io
      restorePVs: true 3
    1
    Backup CR의 이름입니다.
    2
    선택 사항: 복원 프로세스에 포함할 리소스 배열을 지정합니다. 리소스는 바로 가기(예: Pod의 경우) 또는 정규화된일 수 있습니다. 지정하지 않으면 모든 리소스가 포함됩니다.
    3
    선택 사항: restorePVs 매개변수를 false 로 설정하여 VolumeSnapshot of Container Storage Interface(CSI) 스냅샷에서 PersistentVolumes 복원을 끄거나 VolumeSnapshotLocation 이 구성된 경우 기본 스냅샷에서 설정할 수 있습니다.
  2. 다음 명령을 입력하여 Restore CR의 상태가 Completed 인지 확인합니다.

    $ oc get restore -n openshift-adp <restore> -o jsonpath='{.status.phase}'
  3. 다음 명령을 입력하여 백업 리소스가 복원되었는지 확인합니다.

    $ oc get all -n <namespace> 1
    1
    백업한 네임스페이스입니다.
  4. Restic을 사용하여 DeploymentConfig 오브젝트를 복원하거나 post-restore 후크를 사용하는 경우 다음 명령을 입력하여 dc-restic-post-restore.sh cleanup 스크립트를 실행합니다.

    $ bash dc-restic-post-restore.sh <restore-name>
    참고

    복원 프로세스 중에 OADP Velero 플러그인은 DeploymentConfig 오브젝트를 축소하고 Pod를 독립 실행형 포드로 복원합니다. 이 작업은 클러스터가 복원 시 복원된 DeploymentConfig Pod를 즉시 삭제하고 Restic 및 복원 후 후크를 허용하여 복원된 Pod에서 작업을 완료하지 못하도록 하기 위해 수행됩니다. 아래에 표시된 정리 스크립트는 이러한 연결이 끊긴 Pod를 제거하고 적절한 복제본 수로 DeploymentConfig 오브젝트를 다시 확장합니다.

    예 15.1. dc-restic-post-restore.sh cleanup script

    #!/bin/bash
    set -e
    
    # if sha256sum exists, use it to check the integrity of the file
    if command -v sha256sum >/dev/null 2>&1; then
      CHECKSUM_CMD="sha256sum"
    else
      CHECKSUM_CMD="shasum -a 256"
    fi
    
    label_name () {
        if [ "${#1}" -le "63" ]; then
    	echo $1
    	return
        fi
        sha=$(echo -n $1|$CHECKSUM_CMD)
        echo "${1:0:57}${sha:0:6}"
    }
    
    OADP_NAMESPACE=${OADP_NAMESPACE:=openshift-adp}
    
    if [[ $# -ne 1 ]]; then
        echo "usage: ${BASH_SOURCE} restore-name"
        exit 1
    fi
    
    echo using OADP Namespace $OADP_NAMESPACE
    echo restore: $1
    
    label=$(label_name $1)
    echo label: $label
    
    echo Deleting disconnected restore pods
    oc delete pods -l oadp.openshift.io/disconnected-from-dc=$label
    
    for dc in $(oc get dc --all-namespaces -l oadp.openshift.io/replicas-modified=$label -o jsonpath='{range .items[*]}{.metadata.namespace}{","}{.metadata.name}{","}{.metadata.annotations.oadp\.openshift\.io/original-replicas}{","}{.metadata.annotations.oadp\.openshift\.io/original-paused}{"\n"}')
    do
        IFS=',' read -ra dc_arr <<< "$dc"
        if [ ${#dc_arr[0]} -gt 0 ]; then
    	echo Found deployment ${dc_arr[0]}/${dc_arr[1]}, setting replicas: ${dc_arr[2]}, paused: ${dc_arr[3]}
    	cat <<EOF | oc patch dc  -n ${dc_arr[0]} ${dc_arr[1]} --patch-file /dev/stdin
    spec:
      replicas: ${dc_arr[2]}
      paused: ${dc_arr[3]}
    EOF
        fi
    done

15.4.1.1. 복원 후크 생성

Restore CR(사용자 정의 리소스)을 편집하여 Pod의 컨테이너에서 명령을 실행할 복원 후크를 생성합니다.

두 가지 유형의 복원 후크를 생성할 수 있습니다.

  • init 후크는 애플리케이션 컨테이너가 시작되기 전에 설정 작업을 수행하기 위해 Pod에 init 컨테이너를 추가합니다.

    Restic 백업을 복원하는 경우 복원 후크 init 컨테이너 앞에 restic-wait init 컨테이너가 추가됩니다.

  • exec 후크는 복원된 Pod의 컨테이너에서 명령 또는 스크립트를 실행합니다.

절차

  • 다음 예와 같이 Restore CR의 spec.hooks 블록에 후크를 추가합니다.

    apiVersion: velero.io/v1
    kind: Restore
    metadata:
      name: <restore>
      namespace: openshift-adp
    spec:
      hooks:
        resources:
          - name: <hook_name>
            includedNamespaces:
            - <namespace> 1
            excludedNamespaces:
            - <namespace>
            includedResources:
            - pods 2
            excludedResources: []
            labelSelector: 3
              matchLabels:
                app: velero
                component: server
            postHooks:
            - init:
                initContainers:
                - name: restore-hook-init
                  image: alpine:latest
                  volumeMounts:
                  - mountPath: /restores/pvc1-vm
                    name: pvc1-vm
                  command:
                  - /bin/ash
                  - -c
                timeout: 4
            - exec:
                container: <container> 5
                command:
                - /bin/bash 6
                - -c
                - "psql < /backup/backup.sql"
                waitTimeout: 5m 7
                execTimeout: 1m 8
                onError: Continue 9
    1
    선택 사항: 후크가 적용되는 네임스페이스 배열입니다. 이 값을 지정하지 않으면 후크가 모든 네임스페이스에 적용됩니다.
    2
    현재 Pod는 후크를 적용할 수 있는 유일한 지원 리소스입니다.
    3
    선택 사항: 이 후크는 라벨 선택기와 일치하는 오브젝트에만 적용됩니다.
    4
    선택 사항: 시간 초과는 Velero가 initContainers 가 완료될 때까지 대기하는 최대 시간을 지정합니다.
    5
    선택 사항: 컨테이너를 지정하지 않으면 Pod의 첫 번째 컨테이너에서 명령이 실행됩니다.
    6
    이는 추가되는 init 컨테이너의 진입점입니다.
    7
    선택 사항: 컨테이너가 준비될 때까지 대기하는 시간입니다. 컨테이너가 시작되고 동일한 컨테이너의 이전 후크가 완료될 때까지 충분히 길어야 합니다. 설정되지 않은 경우 복원 프로세스는 무기한 대기합니다.
    8
    선택 사항: 명령이 실행될 때까지 대기하는 시간입니다. 기본값은 30s 입니다.
    9
    오류 처리에 허용되는 값은 Fail and Continue 입니다.
    • continue: 명령 실패만 기록됩니다.
    • fail: Pod의 컨테이너에서 더 이상 복원 후크가 실행되지 않습니다. Restore CR의 상태는 PartiallyFailed 가 됩니다.