이 페이지에서는 Google Cloud CLI를 사용하여 Cloud Spanner 백업 및 복원을 사용하는 방법을 설명합니다.
기본 요건
이 페이지의 예시에서는 다음 가정이 사용됩니다.
Cloud Spanner에 사용하도록 gcloud CLI가 이미 설정되었습니다. Cloud Spanner에서 gcloud를 처음 사용하는 경우에는 gcloud를 사용하여 Cloud Spanner 시작하기를 참조하세요.
기본 프로젝트로 gcloud가 구성되어 있습니다. 예를 들면 다음과 같습니다.
gcloud config set core/project my-project
test-instance
라는 인스턴스와example-db
라는 데이터베이스가 있습니다.
백업 만들기
example-db-backup-6
라는 백업을 만들고 만료 기간을 1년으로 설정하려면 다음 안내를 따르세요.
gcloud spanner backups create example-db-backup-6 --instance=test-instance \
--database=example-db --retention-period=1y --async
다음은 몇 가지 사용법 참고사항입니다.
- 백업의 만료 날짜를 설정하려면
--retention-period
또는--expiration-date
플래그를 지정합니다. 날짜 구문에 대한 정보는 gcloud topic datetimes를 참조하세요. - 백업 이름은 인스턴스에서 고유해야 합니다.
- 이 명령어는
--async
플래그로 인해 즉시 반환합니다. 이 플래그가 없으면 백업 작업이 완료될 때까지 명령어가 대기합니다. - 모든 명령어의 도움말을 보려면
--help
플래그를 지정하세요.
출력은 다음과 같습니다.
Create request issued for: [example-db-backup-6]
Check operation [projects/my-project/instances/test-instance/backups/example-db-backup-6/operations/_auto_op_234567] for status.
다음 섹션에서는 백업 작업을 사용하여 백업 진행 상태를 확인합니다.
이 명령어에 대한 자세한 내용은 gcloud spanner backups create를 참조하세요.
백업 진행 상태 표시
백업 작업의 진행 상태를 추적하려면 gcloud spanner operations describe를 사용합니다.
gcloud spanner operations describe _auto_op_234567 \ --instance=test-instance --backup=example-db-backup-6
출력은 다음과 같습니다.
done: true metadata: '@type': type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata database: projects/my-project/instances/test-instance/databases/example-db name: projects/my-project/instances/test-instance/backups/example-db-backup-6 progress: endTime: '2020-02-04T02:07:59.089820Z' progressPercent: 100 startTime: '2020-02-04T02:05:43.920377Z' name: projects/my-project/instances/test-instance/backups/example-db-backup-6/operations/_auto_op_234567 response: '@type': type.googleapis.com/google.spanner.admin.database.v1.Backup createTime: '2020-02-04T02:05:43.920377Z' database: projects/my-project/instances/test-instance/databases/example-db expireTime: '2021-02-04T02:05:43.268327Z' name: projects/my-project/instances/test-instance/backups/example-db-backup-6 sizeBytes: '1000000000' state: READY
작업 이름이 없으면 gcloud spanner operations list를 사용하여 찾습니다.
gcloud spanner operations list --instance=test-instance --type=BACKUP
사용법 참고사항:
목록을 제한하려면
--filter
태그를 지정합니다.- 예를 들어
--filter="metadata.name:example-db"
는 특정 데이터베이스의 백업 작업만 나열합니다. - 예를 들어
--filter="error:*"
는 실패한 백업 작업만 나열합니다.
필터 구문에 대한 자세한 내용은 gcloud topic filters를 참조하세요. 백업 작업 필터링에 대한 자세한 내용은 ListBackupOperationsRequest의
filter
필드를 참조하세요.- 예를 들어
--type
플래그는 대소문자를 구분하지 않습니다.
출력은 다음과 같습니다.
OPERATION_ID DONE @TYPE BACKUP SOURCE_DATABASE START_TIME END_TIME _auto_op_123456 True CreateBackupMetadata example-db-backup-7 example-db 2020-02-04T02:12:38.075515Z 2020-02-04T02:22:40.581170Z _auto_op_234567 True CreateBackupMetadata example-db-backup-6 example-db 2020-02-04T02:05:43.920377Z 2020-02-04T02:07:59.089820Z
백업에서 데이터베이스 복원
데이터베이스를 복원하려면:
gcloud spanner databases restore --async \
--destination-instance=test-instance --destination-database=example-db-restored \
--source-instance=test-instance --source-backup=example-db-backup-6
사용법 참고사항:
- 이 명령어는
--async
플래그로 인해 즉시 반환합니다. 이 플래그가 없으면 복원 작업이 완료될 때까지 명령어가 대기합니다. - 소스 및 대상 인스턴스가 서로 다르면 동일한 인스턴스 구성을 포함해야 합니다.
- 대상 데이터베이스가 이미 있으면 작업이 실패합니다.
출력은 다음과 같습니다.
Restore database in progress. Operation name=projects/my-project/instances/test-instance/databases/example-db-restored-1/operations/_auto_op_bb8e360b256b04bf
이 명령어에 대한 자세한 내용은 gcloud spanner databases restore를 참조하세요.
복원 및 최적화 진행 상태 표시
복원 작업의 진행 상태를 추적하려면 gcloud spanner operations describe를 사용합니다.
gcloud spanner operations describe _auto_op_bb8e360b256b04bf \ --instance=test-instance --database=example-db-restored
출력은 다음과 같습니다.
done: true metadata: '@type': type.googleapis.com/google.spanner.admin.database.v1.RestoreDatabaseMetadata backupInfo: backup: projects/my-project/instances/test-instance/backups/example-db-backup-6 createTime: '2020-02-03T23:48:06.259296Z' sourceDatabase: projects/my-project/instances/test-instance/databases/example-db name: projects/my-project/instances/test-instance/databases/example-db-restored optimizeDatabaseOperationName: projects/my-project/instances/test-instance/databases/example-db-restored/operations/_auto_op_7702f3f19fa99616 progress: endTime: '2020-02-04T02:40:56.424382Z' progressPercent: 100 startTime: '2020-02-04T02:35:30.683330Z' sourceType: BACKUP name: projects/my-project/instances/test-instance/databases/example-db-restored/operations/_auto_op_91ff1f270832a22b response: '@type': type.googleapis.com/google.spanner.admin.database.v1.Database createTime: '2020-02-04T02:35:30.683330Z' name: projects/my-project/instances/test-instance/databases/example-db-restored restoreInfo: backupInfo: backup: projects/my-project/instances/test-instance/backups/example-db-backup-6 createTime: '2020-02-03T23:48:06.259296Z' sourceDatabase: projects/my-project/instances/test-instance/databases/example-db sourceType: BACKUP state: READY_OPTIMIZING
출력에서는 복원 작업이 완료되었고 복원 작업 방법에 설명된 대로 이제
READY_OPTIMIZING
상태인 것을 알 수 있습니다. 또한 최적화 작업의 진행 상태를 추적하는 데 사용할 수 있는optimizeDatabaseOperationName
이 제공됩니다.최적화 작업의 진행 상태를 추적하려면 gcloud spanner operations describe를 사용하세요.
gcloud-testing spanner operations describe _auto_op_7702f3f19fa99616 \ --instance=test-instance --database=example-db-restored
출력은 다음과 같습니다.
done: true metadata: '@type': type.googleapis.com/google.spanner.admin.database.v1.OptimizeRestoredDatabaseMetadata name: projects/my-project/instances/test-instance/databases/example-db-restored progress: endTime: '2020-02-04T22:11:21.731739Z' progressPercent: 100 startTime: '2020-02-04T22:10:48.308090Z' name: projects/my-project/instances/test-instance/databases/example-db-restored/operations/_auto_op_7702f3f19fa99616 response: '@type': type.googleapis.com/google.spanner.admin.database.v1.Database createTime: '2020-02-04T22:03:34.282186Z' name: projects/my-project/instances/test-instance/databases/example-db-restored restoreInfo: backupInfo: backup: projects/my-project/instances/test-instance/backups/example-db-backup-6 createTime: '2020-02-03T23:48:06.259296Z' sourceDatabase: projects/my-project/instances/test-instance/databases/example-db sourceType: BACKUP state: READY
복원 또는 최적화 작업의 이름이 없으면 gcloud spanner operations list를 사용하여 찾습니다. 복원된 데이터베이스가 백업과 동일한 인스턴스에 없으면
instance
플래그에 대상 인스턴스를 지정해야 합니다.gcloud spanner operations list --instance=test-instance \ --type=DATABASE_RESTORE
출력은 다음과 같습니다.
OPERATION_ID DONE @TYPE RESTORED_DATABASE SOURCE_BACKUP START_TIME END_TIME _auto_op_7702f3f19fa99616 True OptimizeRestoredDatabaseMetadata example-db-restored 2020-02-04T02:40:56.424382Z 2020-02-04T02:41:37.765157Z _auto_op_91ff1f270832a22b True RestoreDatabaseMetadata example-db-restored example-db-backup-6 2020-02-04T02:35:30.683330Z 2020-02-04T02:40:56.424382Z
백업 정보 가져오기
백업에 대한 정보를 가져오려면 다음 안내를 따르세요.
gcloud spanner backups describe example-db-backup-6 --instance=test-instance
출력은 다음과 같습니다.
createTime: '2020-02-04T02:05:43.920377Z'
database: projects/my-project/instances/test-instance/databases/example-db
expireTime: '2021-02-04T02:05:43.268327Z'
name: projects/my-project/instances/test-instance/backups/example-db-backup-6
sizeBytes: '1000000000'
state: READY
이 명령어에 대한 자세한 내용은 gcloud spanner backups describe를 참조하세요.
백업 표시
인스턴스의 모든 백업을 나열하려면 다음 안내를 따르세요.
gcloud spanner backups list --instance=test-instance
출력은 다음과 같습니다.
BACKUP SOURCE_DATABASE CREATION_TIME EXPIRATION_TIME STATE BACKUP_SIZE_IN_BYTES IN_USE_BY
example-db-backup-6 example-db 2020-02-04T02:05:43.920377Z 2021-02-04T02:05:43.268327Z CREATING
example-db-backup-4 example-db 2020-02-04T01:21:20.873839Z 2021-02-04T01:21:20.530151Z READY 32
example-db-backup-3 example-db 2020-02-03T23:59:18.936433Z 2021-02-03T23:59:18.203083Z READY 32
example-db-backup-5 example-db 2020-02-03T23:48:06.259296Z 2021-02-03T23:48:05.830937Z READY 32
example-db-backup-2 example-db 2020-01-30T19:49:00.616338Z 2021-01-30T19:49:00.283917Z READY 32
example-db-backup-1 example-db 2020-01-30T19:47:09.492551Z 2021-01-30T19:47:09.097804Z READY 32
목록을 제한하려면 --filter
태그를 지정합니다. 예를 들어 --filter="state:creating"
은 아직 생성 중인 백업만 나열합니다.
필터 구문에 대한 자세한 내용은 gcloud topic filters를 참조하세요.
백업 필터링에 대한 자세한 내용은 ListBackupsRequest의 filter
필드를 참조하세요.
이 명령어에 대한 자세한 내용은 gcloud spanner backups list를 참조하세요.
백업 메타데이터 업데이트
백업의 만료 날짜를 업데이트하려면 다음 안내를 따르세요.
gcloud spanner backups update-metadata example-db-backup-6 \
--instance=test-instance --expiration-date=2020-05-05T00:00:00Z
출력은 다음과 같습니다.
createTime: '2020-02-04T02:05:43.920377Z'
database: projects/my-project/instances/test-instance/databases/example-db
expireTime: '2020-05-05T00:00:00Z'
name: projects/my-project/instances/test-instance/backups/example-db-backup-6
sizeBytes: '1000000000'
state: READY
이 명령어에 대한 자세한 내용은 gcloud spanner backups update-metadata를 참조하세요.
백업 삭제
백업을 삭제하려면 다음 안내를 따르세요.
gcloud spanner backups delete example-db-backup-1 --instance=test-instance
작업을 확인해야 합니다.
You are about to delete backup [example-db-backup-1]
Do you want to continue (Y/n)? Y
Deleted backup [example-db-backup-1].
이 명령어에 대한 자세한 내용은 gcloud spanner backups delete를 참조하세요.