콘텐츠로 이동
AggregaAggrega
언어 선택: 한국어
이 페이지는 기계 번역되었습니다. 영어 원문 읽기.

모든 대상에서 백업되는 데이터 저장소: 하나의 core/backup 첨부

PostgreSQL 데이터베이스를 Kubernetes에서는 Velero와 CloudNativePG를 통해, AWS에서는 Terraform과 CloudFormation에서 Amazon RDS 자체의 자동 백업을 통해, 그리고 AWS Backup을 통해 백업합니다. 모두 운영자가 각 Release에 작성하는 하나의 core/backup 첨부에서 비롯되며, 백업 제품이 없는 대상에서는 거부됩니다.

core/backup은 데이터 저장소가 일정에 따라 백업되고 각 백업이 정해진 일수 동안 보관된다는 것을 나타냅니다. 방법에 대해서는 아무것도 말하지 않습니다. 각 대상의 Manifest가 그 대상에서 이를 실현하는 FeatureRecipe를 바인딩하고, 각 FeatureRecipe는 자체 제품의 용어로 백업을 작성합니다. Velero 일정, CloudNativePG 예약 백업, RDS 인스턴스의 설정, AWS Backup 계획이 그것입니다. 이를 실현할 제품이 없는 대상은 첨부를 이름으로 지목하여 거부하므로, 빌드는 백업이 작성되지 않은 데이터 저장소를 배포하는 대신 중단됩니다.

이 작업 공간은 하나의 Aggregate를 여섯 개의 Releases를 통해 빌드하며, 각각 같은 백업을 첨부합니다. 매일 02:30에 실행되고 각 백업은 14일 동안 보관됩니다. 이 페이지는 완료되는 다섯 개에서 각 대상이 이를 위해 렌더링하는 내용을 보여 주고, 중단될 것으로 예상되는 여섯 번째가 출력하는 내용을 인용합니다.

구성되는 내용

인스턴스카탈로그 Component실행 위치
dbcore/datastore/postgres모든 Release
backupscore/storage/s3-object-store두 Kubernetes Releases: 백업이 저장되는 버킷
velerocore/storage/veleroVelero Release
barman-cloudcore/storage/barman-cloud-pluginCloudNativePG Release

Aggregate는 데이터베이스와, Kubernetes에서 그 백업에 필요한 것, 즉 버킷 하나와 백업 컨트롤러 두 개를 선언합니다. 백업 컨트롤러는 데이터베이스와 함께가 아니라 클러스터당 한 번 설치되므로 별도의 구성 요소입니다. AWS에서는 백업이 관리형 서비스 자체의 스토리지에 보관되므로 셋 중 어느 것도 필요하지 않습니다. 하나의 매개변수 backup_controller가 각 구성 요소의 active: 토글을 통해 이들을 전환합니다.

aggregate.yaml
spec:
parameters:
[… omitted: the comment above the parameter]
backup_controller:
type: string
default: none
[… omitted: the parameter's description]
components:
[… omitted: the comment above each component]
db:
type: core/datastore/postgres
backups:
type: core/storage/s3-object-store
active: '{{ ne .parameters.backup_controller "none" }}'
values:
bucket: db-backups
velero:
type: core/storage/velero
active: '{{ eq .parameters.backup_controller "velero" }}'
barman-cloud:
type: core/storage/barman-cloud-plugin
active: '{{ eq .parameters.backup_controller "cloudnative-pg" }}'

토글이 false인 구성 요소는 무엇이든 빌드되기 전에 제거되므로, 매개변수를 none으로 두는 AWS 및 Docker Compose Releases는 데이터베이스만 빌드합니다.

첨부

개발자는 백업을 위해 아무것도 작성하지 않습니다. db는 Aggregate에서 첨부를 갖지 않습니다. 운영자가 각 Release에서 구성 요소의 features 아래에 core/backup을 첨부하고, 그곳에서 백업이 언제 실행되고 각 백업을 얼마나 오래 보관할지 지정합니다. Kubernetes에서는 첨부가 버킷에 대한 store 연결을 통해 백업이 저장될 위치도 지정합니다.

release-helm-velero.yaml
components:
db:
annotations:
aggrega.ai/namespace: orders
[… omitted: the comment above the attachment]
features:
backup:
type: core/backup
infra:
schedule: "30 2 * * *"
retention_days: 14
uses:
store:
bucket:
target: backups

AWS Releases는 같은 첨부를 store 연결 없이 작성합니다. RDS와 AWS Backup은 자체 스토리지에 백업을 보관하며, 그곳의 실현은 아무것도 기록되지 않을 버킷에 대한 연결을 거부하기 때문입니다. AWS Backup Release는 AWS Backup이 각 백업을 실행할 때 사용하는 IAM 역할인 infra.role_arn을 추가합니다.

여섯 개의 Releases

ReleaseManifestcore/backup 실현 주체빌드
release-helm-velero.yamlmanifest-helm-velero.yamlhelm/backup-velero완료됨
release-helm-cloudnative-pg.yamlmanifest-helm-cloudnative-pg.yamlhelm/backup-cloudnative-pg완료됨
release-terraform.yamlmanifest-terraform.yamlterraform/backup-native완료됨
release-cloudformation.yamlmanifest-cloudformation.yamlcloudformation/backup-native완료됨
release-terraform-aws-backup.yamlmanifest-terraform-aws-backup.yamlterraform/backup-aws-backup완료됨
release-compose.yamlmanifest-compose.yaml없음중단됨

어떤 제품이 데이터베이스를 백업할지는 Manifest가 결정합니다. 두 Kubernetes Manifests는 데이터베이스를 두 가지 방식으로 실행하며(Velero용으로는 StatefulSet인 helm/postgres, 플러그인용으로는 CloudNativePG Cluster인 helm/postgres-cloudnative-pg), 각각에 대해 백업의 실현을 바인딩합니다. manifest-terraform.yaml과 manifest-terraform-aws-backup.yaml은 데이터베이스를 같은 Recipe에 매핑하고 core/backup에 바인딩하는 FeatureRecipe만 다르며, 이들로부터 빌드되는 Releases는 각각이 지정하는 Manifest 외에는 역할만 다릅니다.

Kubernetes Releases는 버킷 자체의 키 쌍과 Velero가 요청에 서명하는 데 쓰는 자격 증명 파일도, 클러스터가 이미 보유한 Secrets를 지정하는 core/referenced-secret 첨부로 첨부하므로, 어떤 렌더링된 파일에도 키가 기록되지 않습니다. AWS Releases의 모든 계정별 값은 자리 표시자입니다.

예제 생성하기

아래 명령으로 이 예제를 빌드하거나, AI 어시스턴트에게 대신 빌드하게 할 수 있습니다.

예제 이름을 딴 새 폴더에 예제를 씁니다:

Terminal window
aggrega scaffold --example datastore-backup

그런 다음 이어서 실행할 명령을 출력합니다. 첫 번째 명령은 새 폴더로 이동합니다:

Terminal window
cd datastore-backup

빌드

작업 공간은 .aggrega-config.yaml이 지정하는 허브 레지스트리에서 표준 라이브러리 카탈로그를 읽습니다. Velero와 Barman Cloud 플러그인은 각 프로젝트 자체의 차트로 설치되므로, 두 Kubernetes Releases는 빌드에서 해당 프로젝트의 차트 저장소에 도달할 수 있어야 합니다. 그 밖의 모든 Release는 카탈로그만으로 렌더링됩니다.

Terminal window
aggrega build --release release-helm-velero.yaml --auto-pull # one Release

문서 저장소의 체크아웃(aggrega scaffold --example로 작성된 사본에는 없는 공유 빌드 헬퍼가 들어 있음)에서는 ./check.sh가 여섯 Releases를 모두 빌드하고 각 결과를 확인합니다. Release마다 한 줄을 출력하고, 각각이 이 페이지에서 설명하는 대로 끝났을 때만 0으로 종료합니다.

RELEASE EXIT EXPECTED VERDICT
----------------------------------------------------------------------------------------------------
release-helm-velero.yaml 0 complete OK: completed, the backup the README shows
release-helm-cloudnative-pg.yaml 0 complete OK: completed, the backup the README shows
release-terraform.yaml 0 complete OK: completed, the backup the README shows
release-cloudformation.yaml 0 complete OK: completed, the backup the README shows
release-terraform-aws-backup.yaml 0 complete OK: completed, the backup the README shows
release-compose.yaml 1 halt OK: halted with the expected refusal
check: every build ended as expected.

AI 어시스턴트 사용

Aggrega 도구로 설정한 AI 어시스턴트도 같은 작업을 할 수 있습니다. 다음 프롬프트를 붙여 넣으십시오.

Aggrega 도구만 사용하고, 폴더는 직접 만들지 마십시오. 작업 영역 폴더에 아직 `datastore-backup` 폴더가 없으면 `example`을 `datastore-backup`으로 설정하고 `dir`은 지정하지 않은 채 `scaffold` 도구를 한 번 호출하십시오. 이 도구는 예제를 새 `datastore-backup` 폴더에 씁니다. 그런 다음 `workspace_root`를 `datastore-backup`으로, `release`를 `release-helm-velero.yaml`로, `auto_pull`을 true로, `write`를 true로 설정하여 `build` 도구를 호출하십시오. 빌드가 쓴 파일을 알려 주십시오. 파일은 `datastore-backup/dist/` 아래에 있습니다.

Kubernetes, Velero 사용

release-helm-velero.yaml은 데이터베이스의 StatefulSet과 Services, 버킷의 리소스, Velero 자체 차트가 렌더링하는 객체, 그리고 첨부를 위한 파일 하나를 작성하며, 이 파일에는 Velero 스토리지 위치와 일정이 들어 있습니다.

dist/helm/db--backup--backup.yaml
apiVersion: velero.io/v1
kind: BackupStorageLocation
metadata:
[… omitted: the labels and annotations the build writes on every resource]
name: "orders-db-backup"
namespace: velero
spec:
provider: velero.io/aws
objectStorage:
bucket: "db-backups"
prefix: "orders-db-backup"
config:
region: "us-east-1"
s3Url: "http://backups-default.orders:8333"
s3ForcePathStyle: "true"
---
apiVersion: velero.io/v1
kind: Schedule
metadata:
[… omitted: the labels and annotations, as on the storage location]
name: "orders-db-backup"
namespace: velero
spec:
schedule: "30 2 * * *"
template:
includedNamespaces:
- "orders"
orLabelSelectors:
- matchLabels:
"app": "db"
storageLocation: "orders-db-backup"
ttl: "336h0m0s"
snapshotVolumes: false
defaultVolumesToFsBackup: true

둘 다 Velero가 일정을 읽는 유일한 네임스페이스인 velero에 위치하며, 클러스터의 모든 Release가 그 하나의 네임스페이스에 기록하므로 데이터베이스의 네임스페이스, 이름, 첨부의 이름을 따서 이름이 지어집니다. 일정은 데이터베이스가 렌더링하는 StatefulSet의 레이블로, 데이터베이스가 배치된 네임스페이스에서 데이터베이스의 파드를 선택하며, Velero의 노드 에이전트가 그 볼륨의 파일을 버킷으로 복사합니다. 버킷의 주소는 backups 구성 요소가 게시하는 주소로, Velero가 다른 네임스페이스에서 실행되므로 Service 이름이 실행 중인 네임스페이스로 한정됩니다. 리전도 버킷의 것입니다. 여기서 버킷을 실행하는 SeaweedFS는 리전을 읽지 않으며 us-east-1을 게시합니다. 14일은 Velero의 TTL(time to live)로, 시간 단위로 표시됩니다.

Kubernetes, CloudNativePG 사용

release-helm-cloudnative-pg.yaml은 데이터베이스를 CloudNativePG Cluster로 작성하고, 버킷, 플러그인 차트가 렌더링하는 객체, 첨부의 파일을 작성합니다. 이 파일에는 플러그인의 객체 저장소와 예약 백업이 들어 있으며, Cluster와 함께 자체 네임스페이스에 위치합니다.

dist/helm/db--backup--backup.yaml
apiVersion: barmancloud.cnpg.io/v1
kind: ObjectStore
metadata:
[… omitted: the labels and annotations the build writes on every resource]
name: "db-backup"
namespace: "orders"
spec:
configuration:
destinationPath: "s3://db-backups/orders/db-backup"
endpointURL: "http://backups-default.orders:8333"
s3Credentials:
accessKeyId:
name: "db-backup"
key: "ACCESS_KEY_ID"
secretAccessKey:
name: "db-backup"
key: "ACCESS_SECRET_KEY"
retentionPolicy: "14d"
instanceSidecarConfiguration:
env:
- name: "AWS_DEFAULT_REGION"
value: "us-east-1"
---
apiVersion: postgresql.cnpg.io/v1
kind: ScheduledBackup
metadata:
[… omitted: the labels and annotations, as on the object store]
name: "db-backup"
namespace: "orders"
spec:
schedule: "0 30 2 * * *"
cluster:
name: "db"
method: "plugin"
pluginConfiguration:
name: "barman-cloud.cloudnative-pg.io"

CloudNativePG 일정에는 필드가 여섯 개 있고 첫 번째는 초를 나타내므로, 첨부의 30 2 * * *는 앞에 0을 붙여 작성됩니다. 첨부가 infra.credentials_secret을 설정하지 않으므로, 플러그인은 객체 저장소가 지정하는 Secret(여기서는 객체 저장소 자체의 이름을 딴 db-backup)의 키 쌍으로 요청에 서명합니다.

데이터베이스 자체의 Recipe도 첨부를 읽고, 플러그인을 Cluster의 선행 기록 로그(WAL) 아카이버로 지정합니다.

dist/helm/db/cluster.yaml
[… omitted: apiVersion, kind and metadata]
spec:
[… omitted: the instance count, the image, the storage and the resources]
plugins:
- name: "barman-cloud.cloudnative-pg.io"
isWALArchiver: true
parameters:
barmanObjectName: "db-backup"
[… omitted: the bootstrap settings]

따라서 로그는 매일의 기본 백업 사이에도 지속적으로 버킷에 아카이브되며, 복원은 14일 중 어느 시점에도 도달할 수 있습니다. 이것이 CloudNativePG의 특정 시점 복구이며, 이 실현은 이를 켜 둔 상태로 유지합니다.

Terraform

release-terraform.yaml은 데이터베이스의 모듈만 작성합니다. 첨부의 실현인 terraform/backup-native는 파일을 렌더링하지 않습니다. 백업은 RDS 인스턴스의 설정이므로, 데이터베이스의 Recipe가 첨부를 읽어 인스턴스가 작성되는 곳에 이를 작성합니다.

dist/terraform/modules/db/main.tf
[… omitted: the provenance comment, the provider requirement, and the instance's engine, compute, storage, database and HA arguments]
## ── Backup ───────────────────────────────────────────────
backup_retention_period = 14
backup_window = "02:30-03:00"
[… omitted: the subnet group and security groups, and the address output]

RDS는 cron 표현식 대신 하루 한 번의 시작 시각을 받으므로, 30 2 * * *는 UTC 02:30에 열리고 30분 동안 지속되는 백업 창이 됩니다. 이는 RDS가 받아들이는 가장 짧은 길이입니다.

CloudFormation

release-cloudformation.yaml은 인스턴스를 담은 스택 템플릿 하나를 작성하며, 같은 두 설정을 CloudFormation 속성 이름으로 기록합니다.

dist/cloudformation/cloudformation-stack.json
[… omitted: the template's format version, the outputs carrying what the database publishes, and the opening of its resources]
"Db": {
[… omitted: the deletion policy and the provenance metadata]
"Properties": {
"AllocatedStorage": 10,
"BackupRetentionPeriod": 14,
"DBInstanceClass": "db.t3.small",
[… omitted: the database name, the subnet group, the engine and the credentials settings]
"MultiAZ": false,
"Port": 5432,
"PreferredBackupWindow": "02:30-03:00",
[… omitted: the storage type and the security groups]
},
"Type": "AWS::RDS::DBInstance"
}
[… omitted: the closing of the resources and of the template]

AWS Backup

release-terraform-aws-backup.yaml은 대신 terraform/backup-aws-backup을 바인딩하는 Manifest로부터 빌드됩니다. 이 실현은 데이터베이스의 모듈 옆에 첨부 자체의 모듈을 작성하며, 여기에는 백업 볼트, 계획, 그리고 인스턴스를 지정하는 선택이 들어 있습니다.

dist/terraform/modules/db--backup/backup.tf
[… omitted: the provenance comment, the provider requirement, and the partition, Region and account lookups]
resource "aws_backup_vault" "backup" {
name = "db-backup"
}
resource "aws_backup_plan" "backup" {
name = "db-backup"
rule {
rule_name = "db-backup"
target_vault_name = aws_backup_vault.backup.name
schedule = "cron(30 2 * * ? *)"
start_window = 60
lifecycle {
delete_after = 14
}
}
}
resource "aws_backup_selection" "backup" {
name = "db-backup"
plan_id = aws_backup_plan.backup.id
iam_role_arn = "arn:aws:iam::123456789012:role/example-backup"
resources = [
"arn:${data.aws_partition.current.partition}:rds:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:db:db",
]
}

일정은 AWS 자체의 cron 형식으로 작성되어 UTC로 해석되며, 예정 시각으로부터 한 시간 이내에 시작되지 않은 백업은 시작되지 않습니다. 인스턴스의 ARN은 AWS 프로바이더가 계획 시점에 구성된 내용과 인스턴스 이름으로 조합된 Terraform 표현식이며, 역할은 Release가 지정한 것으로 작성된 그대로 전달됩니다.

인스턴스는 첨부가 없을 때와 마찬가지로 AWS Backup의 백업과 별도로 자체 자동 백업을 유지합니다. 7일 동안, RDS가 선택하는 창에서 실행됩니다. 첨부의 일정은 인스턴스가 아니라 AWS Backup의 것이기 때문입니다.

dist/terraform/modules/db/main.tf
[… omitted: the provenance comment, the provider requirement, and the instance's engine, compute, storage, database and HA arguments]
## ── Backup ───────────────────────────────────────────────
backup_retention_period = 7
[… omitted: the subnet group and security groups, and the address output]

첨부에 infra.keep_automated_backups: false를 지정하면 이를 끄고 AWS Backup의 백업만 인스턴스의 유일한 백업으로 남깁니다.

빌드가 하지 않는 일

빌드는 파일을 작성하고 멈춥니다. 백업을 실행하지 않으며 어떤 클러스터, 버킷, AWS API에도 접근하지 않습니다. ARN, 계정, 리전도 해석하지 않습니다. AWS에서 각각은 표현식이거나 Release가 작성한 값이며, 파일이 적용될 때 Terraform, CloudFormation 또는 AWS가 읽습니다. 클러스터 안의 어떤 것도 확인하지 않습니다.

  • Velero의 일정은 Velero가 배포된 곳에서만 실행되고, 플러그인의 백업은 플러그인, CloudNativePG 오퍼레이터(1.26 이상), cert-manager가 실행되는 곳에서만 실행됩니다. 이 작업 공간은 Velero와 플러그인을 배포하며, 오퍼레이터와 cert-manager는 이미 있다고 가정합니다.
  • Kubernetes Releases가 지정하는 Secrets는 각각을 읽는 네임스페이스에서 클러스터가 보유해야 합니다. backup-store-access-key-id와 backup-store-secret-access-key는 버킷 옆에, AWS 공유 자격 증명 파일을 담은 velero-cloud-credentials는 velero에, 키 쌍을 ACCESS_KEY_ID와 ACCESS_SECRET_KEY 아래에 담은 db-backup은 데이터베이스 옆에 있습니다. 빌드는 이들 중 어느 것도 렌더링하지 않습니다.

중단되는 Release

release-compose.yaml은 Docker Compose에서 같은 백업을 데이터베이스에 첨부합니다. 그곳에서는 core/backup을 실현하는 FeatureRecipe가 없으므로 manifest-compose.yaml은 아무것도 바인딩하지 않으며, aggrega build --release release-compose.yaml --auto-pull은 백업 없는 데이터베이스를 배포하는 대신 첨부를 지목하며 중단됩니다.

[… omitted: what resolving the lockfile prints, the same halt among it]
[OPS_ERROR E0099]
recipe resolution
caused by (1):
no recipe resolved for component/feature instance: add an explicit Manifest mapping for its type: feature "backup" (type "core/backup"); no feature recipe the lockfile pins implements core/backup:1.0.0 for capability "compose", the capability its component's Recipe binds to; with no catalog directory, the feature recipes searched are only those the lockfile pins, not a registry's; pin one a registry publishes in the Manifest, where one for another capability renders as its own output beside the component's, or write one for "compose", then map the type to it

이 워크스페이스는 카탈로그 디렉터리를 지정하지 않으므로 빌드가 검색할 수 있는 것은 잠금 파일이 고정한 FeatureRecipes뿐이며, core/backup에 대해 아무것도 바인딩하지 않는 Manifest는 아무것도 고정하지 않습니다. 메시지는 허브에 아무것도 없다고 주장하는 대신 이 사실을 밝힙니다. 표준 라이브러리 카탈로그의 체크아웃을 카탈로그 디렉터리로 지정하면, 같은 중단은 카탈로그의 어떤 FeatureRecipe도 compose에 대해 core/backup:1.0.0을 구현하지 않는다고 알리고, 다른 대상에 대해 이를 구현하는 열 개를 나열합니다: cloudformation/backup-aws-backup, cloudformation/backup-native, helm/backup-cloudnative-pg, helm/backup-k8up, helm/backup-kasten, helm/backup-kubestash, helm/backup-mariadb-operator, helm/backup-velero, terraform/backup-aws-backup, terraform/backup-native.

표준 라이브러리 카탈로그에는 이 대상에 대한 core/backup의 FeatureRecipe가 없습니다. 그 각각은 다른 대상에 바인딩되므로, 여기에 고정하면 이 Release가 배포하지 않는 대상을 위해 Compose 파일 옆에 별도의 출력으로 렌더링됩니다. 해결 방법은 Release에서 첨부를 제거하여 그곳에 백업 없이 데이터베이스를 배포하거나, 다른 다섯 Releases처럼 백업 제품이 있는 대상을 위한 Manifest를 통해 배포하는 것입니다.