您可以通過Terraform命令行在備份集群和恢復集群中部署備份倉庫、應用備份、應用恢復的CR資源,以實現跨集群間應用的遷移。
前提條件
已創建ACK集群,且集群版本為1.18及以上版本。具體操作,請參見創建ACK托管版集群。
已安裝備份服務組件并完成對應權限的配置。具體操作,請參見安裝migrate-controller備份服務組件并配置權限。您也可以使用Terraform安裝組件。
已創建用于存儲備份的OSS Bucket,并以
cnfs-oss-*
格式命名。具體操作,請參見使用Terraform管理OSS、alicloud_oss_bucket。若需要使用存儲卷備份,還需要開通ECS快照服務和HBR云備份服務。相關信息,請參見開通OSS服務、開通快照、開通云備份。
注意事項
請勿通過kubectl的
delete
命令刪除備份及恢復任務,避免相關云資源刪除不徹底。備份相關的刪除操作,請參見下文步驟五:刪除集群備份中心的相關資源。關注備份中心組件migrate-controller版本發布情況,并及時升級。具體操作,請參見管理組件。
請勿刪除下文示例代碼中出現的配置參數,以免備份恢復失敗。
步驟一:關聯集群
您可以通過Kubernetes Provider關聯集群,關于Provider更多信息,請參見Kubernetes Provider。
本示例以使用KubeConfig文件為例介紹如何關聯集群。
創建Terraform工作目錄。
在Terraform工作目錄中創建名為csdr.tf配置文件,并在該配置文件中加入以下內容,用于關聯KubeConfig文件。
provider "kubernetes" { config_path = "~/.kube/config" }
執行以下命令,初始化Terraform運行環境。
terraform init
返回信息如下,表明Terraform初始化成功。
Initializing the backend... Initializing provider plugins... - Reusing previous version of hashicorp/alicloud from the dependency lock file - Reusing previous version of hashicorp/kubernetes from the dependency lock file - Using previously-installed hashicorp/alicloud v1.223.1 - Using previously-installed hashicorp/kubernetes v2.30.0 ? │ Warning: Additional provider information from registry │ │ The remote registry returned warnings for registry.terraform.io/hashicorp/alicloud: │ - For users on Terraform 0.13 or greater, this provider has moved to aliyun/alicloud. Please │ update your source in required_providers. ? Terraform has been successfully initialized!
步驟二:創建備份倉庫
在csdr.tf配置文件中加入以下內容,并根據實際需求修改。
resource "kubernetes_manifest" "backuplocation-demo" { manifest = { apiVersion = "csdr.alibabacloud.com/v1beta1" kind = "BackupLocation" metadata = { name = "<yourBackuplocationName>" namespace = "csdr" } spec = { backupSyncPeriod = "0s" config = { network = "internal" region = "cn-beijing" } objectStorage = { bucket = "<cnfs-oss-yourBucketName>" prefix = "<subDir>" } provider = "alibabacloud" } } wait { fields = { "status.phase" = "Available" } } timeouts { create = "10m" } }
參數
是否必選
說明
name
是
備份倉庫的名稱,須符合K8s命名規則。
network
是
OSS Bucket的網絡訪問方式。取值:
internal:內網訪問模式,所有關聯集群與OSS Bucket需處于同一地域。
public:公網訪問模式,無地域限制。
region
是
OSS Bucket所在地域。
bucket
是
OSS Bucket名稱,需提前創建,且名稱需符合以cnfs-oss-****開頭的命名規則。
prefix
否
OSS Bucket子目錄。設定該參數后,實際備份內容存儲在此子目錄下。
執行以下命令,生成資源規劃。
terraform plan
返回信息如下,表明資源規劃生成成功。
# kubernetes_manifest.backuplocation-demo will be created + resource "kubernetes_manifest" "backuplocation-demo" { + manifest = { + apiVersion = "csdr.alibabacloud.com/v1beta1" + kind = "BackupLocation" + metadata = { + name = "<yourBackuplocationName>" + namespace = "csdr" } + spec = { + backupSyncPeriod = "0s" + config = { + network = "internal" + region = "cn-beijing" } + objectStorage = { + bucket = "<cnfs-oss-yourBucketName>" + prefix = "<subDir>" } + provider = "alibabacloud" } } + object = { + apiVersion = "csdr.alibabacloud.com/v1beta1" + kind = "BackupLocation" + metadata = { + annotations = (known after apply) + creationTimestamp = (known after apply) + deletionGracePeriodSeconds = (known after apply) + deletionTimestamp = (known after apply) + finalizers = (known after apply) + generateName = (known after apply) + generation = (known after apply) + labels = (known after apply) + managedFields = (known after apply) + name = "<yourBackuplocationName>" + namespace = "csdr" + ownerReferences = (known after apply) + resourceVersion = (known after apply) + selfLink = (known after apply) + uid = (known after apply) } + spec = { + accessMode = (known after apply) + backupSyncPeriod = "0s" + config = { + network = "internal" + region = "cn-beijing" } + objectStorage = { + bucket = "<cnfs-oss-yourBucketName>" + caCert = (known after apply) + prefix = "<subDir>" } + provider = "alibabacloud" + validationFrequency = (known after apply) } } + timeouts { + create = "10m" } + wait { + fields = { + "status.phase" = "Available" } } }
執行以下命令,創建備份倉庫。
terraform apply
返回信息如下,表明備份倉庫創建成功。
kubernetes_manifest.backuplocation-demo: Creating... kubernetes_manifest.backuplocation-demo: Creation complete after 1s Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
步驟三:創建備份任務
創建立即備份任務
在csdr.tf配置文件中加入以下內容,并根據實際需求修改。
resource "kubernetes_manifest" "applicationbackup-demo" { manifest = { apiVersion = "csdr.alibabacloud.com/v1beta1" kind = "ApplicationBackup" metadata = { name = "<yourApplicationBackupName>" namespace = "csdr" annotations = { "csdr.alibabacloud.com/backuplocations" = "{\"name\":\"<yourBackuplocationName>\",\"region\":\"cn-beijing\",\"bucket\":\"<cnfs-oss-yourBucketName>\",\"prefix\":\"<subDir>\",\"provider\":\"alibabacloud\"}" } spec = { includedNamespaces = ["default","default1"] includedResources = ["statefulset"] excludedResources = ["excludedResources"] labelSelector = { matchLabels = { "app" = "mysql-sts" } } pvBackup = { defaultPvBackup = "false" } storageLocation = "<yourBackuplocationName>" ttl = "720h0m0s" includeClusterResources = "false" } } #備份成功完成的標志為status.phase轉化為Completed階段 #備份時長與集群應用數量、存儲卷數據量有關 #wait { # fields = { # "status.phase" = "Completed" # } #} #timeouts { # create = "60m" #} } }
參數
是否必選
說明
csdr.alibabacloud.com/backuplocations
是
備份所在的備份倉庫信息,需與備份倉庫的配置一致。
name
是
立即備份任務的名稱。
includedNamespaces
是
指定命名空間名稱。
includedResources
否
指定集群資源類型。
重要為避免非預期備份結果,includedResources和excludedResources您只需配置一項。當兩者均為空時,表示備份所有資源類型。
excludedResources
否
排除集群資源類型。
重要為避免非預期備份結果,includedResources和excludedResources您只需配置一項。當兩者均為空時,表示備份所有資源類型。
matchLabels
否
指定標簽,只備份符合的資源。
defaultPvBackup
是否備份存儲卷,開啟數據備份。取值:
true:備份應用和存儲卷。
false:只備份應用。
storageLocation
是
備份倉庫名稱。
說明若您的集群已使用Velero,請加入釘釘用戶群(釘釘群號:35532895)咨詢。
ttl
是
備份有效期,即備份任務的數據存儲有效期,過期之后數據將無法恢復。格式如720h0m0s,取值范圍:24h0m0s~1572864h0m0s。
執行以下命令,生成資源規劃。
terraform plan
返回信息如下,表明資源規劃生成成功。
# kubernetes_manifest.applicationbackup-demo will be created + resource "kubernetes_manifest" "applicationbackup-demo" { + manifest = { + apiVersion = "csdr.alibabacloud.com/v1beta1" + kind = "ApplicationBackup" + metadata = { + annotations = { + "csdr.alibabacloud.com/backuplocations" = "{name:<yourBackuplocationName>,region:cn-beijing,bucket:<cnfs-oss-yourBucketName>,prefix:<subDir>,provider:alibabacloud}" } + name = "<yourApplicationBackupName>" + namespace = "csdr" } + spec = { + excludedResources = [ + "excludedResources", ] + includedNamespaces = [ + "default", + "default1", ] + includedResources = [ + "statefulset", ] + labelSelector = { + matchLabels = { + app = "mysql-sts" } } + pvBackup = { + defaultPvBackup = "false" } + storageLocation = "vault-a" + ttl = "720h0m0s" } } + object = { + apiVersion = "csdr.alibabacloud.com/v1beta1" + kind = "ApplicationBackup" + metadata = { + annotations = (known after apply) + creationTimestamp = (known after apply) + deletionGracePeriodSeconds = (known after apply) + deletionTimestamp = (known after apply) + finalizers = (known after apply) + generateName = (known after apply) + generation = (known after apply) + labels = (known after apply) + managedFields = (known after apply) + name = "<yourApplicationBackupName>" + namespace = "csdr" + ownerReferences = (known after apply) + resourceVersion = (known after apply) + selfLink = (known after apply) + uid = (known after apply) } + spec = { + backupType = (known after apply) + excludedNamespaces = (known after apply) + excludedResources = [ + "excludedResources", ] + includeClusterResources = (known after apply) + includedNamespaces = [ + "default", + "default1", ] + includedResources = [ + "statefulset", ] + labelSelector = { + matchExpressions = (known after apply) + matchLabels = { + app = "mysql-sts" } } + orderedResources = (known after apply) + pvBackup = { + defaultPvBackup = false + pvcList = (known after apply) + pvcSelector = { + matchExpressions = (known after apply) + matchLabels = (known after apply) } + snapshotPostRule = (known after apply) + snapshotPreRule = (known after apply) } + storageLocation = "<yourBackuplocationName>" + ttl = "720h0m0s" } } }
執行以下命令,創建立即備份任務。
terraform apply
返回信息如下,表明立即備份任務創建成功。
kubernetes_manifest.applicationbackup-demo: Creating... kubernetes_manifest.applicationbackup-demo: Creation complete after 1s Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
創建定時備份計劃
在csdr.tf配置文件中加入以下內容,并根據實際需求修改。
resource "kubernetes_manifest" "backupschedule-demo" { manifest = { apiVersion = "csdr.alibabacloud.com/v1beta1" kind = "BackupSchedule" metadata = { name = "<yourBackupScheduleName>" namespace = "csdr" annotations = { "csdr.alibabacloud.com/backuplocations" = "{\"name\":\"<yourBackuplocationName>\",\"region\":\"cn-beijing\",\"bucket\":\"<cnfs-oss-yourBucketName>\",\"prefix\":\"<subDir>\",\"provider\":\"alibabacloud\"}" } } spec = { schedule = "1 4 * * *" template = { includedNamespaces = ["default","default1"] includedResources = ["statefulset"] excludedResources = ["excludedResources"] labelSelector = { matchLabels = { "app" = "mysql-sts" } } pvBackup = { defaultPvBackup = "false" } storageLocation = "<yourBackuplocationName>" ttl = "720h0m0s" includeClusterResources = "false" } } } wait { fields = { "status.phase" = "Enabled" } } timeouts { create = "10m" } }
參數
是否必選
說明
csdr.alibabacloud.com/backuplocations
是
備份所在的備份倉庫信息,需與備份倉庫的配置一致。
name
是
定時備份計劃的名稱。
schedule
是
備份周期,請使用Cron表達式。
includedNamespaces
是
指定命名空間名稱。
includedResources
否
指定集群資源類型。
重要為避免非預期備份結果,includedResources和excludedResources您只需配置一項。當兩者均為空時,表示備份所有資源類型。
excludedResources
否
排除集群資源類型。
重要為避免非預期備份結果,includedResources和excludedResources您只需配置一項。當兩者均為空時,表示備份所有資源類型。
matchLabels
否
指定標簽,只備份符合條件的資源。
defaultPvBackup
是
是否備份存儲卷,開啟數據備份。取值:
true:備份應用和存儲卷。
false:只備份應用。
storageLocation
是
備份倉庫名稱。
說明若您的集群已使用Velero,請加入釘釘用戶群(釘釘群號:35532895)咨詢。
ttl
是
備份有效期,即備份任務的數據存儲有效期,過期之后數據將無法恢復。格式如720h0m0s,取值范圍:24h0m0s~1572864h0m0s。
執行以下命令,生成資源規劃。
terraform plan
返回信息如下,表明資源規劃生成成功。
# kubernetes_manifest.backupschedule-demo will be created + resource "kubernetes_manifest" "backupschedule-demo" { + manifest = { + apiVersion = "csdr.alibabacloud.com/v1beta1" + kind = "BackupSchedule" + metadata = { + annotations = { + "csdr.alibabacloud.com/backuplocations" = "{name:<yourBackuplocationName>,region:cn-beijing,bucket:<cnfs-oss-yourBucketName>,prefix:<subDir>,provider:alibabacloud}" } + name = "<yourBackupscheduleName>" + namespace = "csdr" } + spec = { + schedule = "1 4 * * *" + template = { + excludedResources = [ + "excludedResources", ] + includedNamespaces = [ + "default", + "default1", ] + includedResources = [ + "statefulset", ] + labelSelector = { + matchLabels = { + app = "mysql-sts" } } + pvBackup = { + defaultPvBackup = "false" } + storageLocation = "<yourBackuplocationName>" + ttl = "720h0m0s" } } } + object = { + apiVersion = "csdr.alibabacloud.com/v1beta1" + kind = "BackupSchedule" + metadata = { + annotations = (known after apply) + creationTimestamp = (known after apply) + deletionGracePeriodSeconds = (known after apply) + deletionTimestamp = (known after apply) + finalizers = (known after apply) + generateName = (known after apply) + generation = (known after apply) + labels = (known after apply) + managedFields = (known after apply) + name = "<yourBackupscheduleName>" + namespace = "csdr" + ownerReferences = (known after apply) + resourceVersion = (known after apply) + selfLink = (known after apply) + uid = (known after apply) } + spec = { + backupAll = (known after apply) + paused = (known after apply) + schedule = "1 4 * * *" + template = { + backupType = (known after apply) + excludedNamespaces = (known after apply) + excludedResources = [ + "excludedResources", ] + includeClusterResources = (known after apply) + includedNamespaces = [ + "default", + "default1", ] + includedResources = [ + "statefulset", ] + labelSelector = { + matchExpressions = (known after apply) + matchLabels = { + app = "mysql-sts" } } + orderedResources = (known after apply) + pvBackup = { + defaultPvBackup = false + pvcList = (known after apply) + pvcSelector = { + matchExpressions = (known after apply) + matchLabels = (known after apply) } + snapshotPostRule = (known after apply) + snapshotPreRule = (known after apply) } + storageLocation = "<yourBackuplocationName>" + ttl = "720h0m0s" } } } + timeouts { + create = "10m" } + wait { + fields = { + "status.phase" = "Enabled" } } }
執行以下命令,創建定時備份計劃。
terraform apply
返回信息如下,表明定時備份計劃創建成功。
kubernetes_manifest.backupschedule-demo: Creating... kubernetes_manifest.backupschedule-demo: Creation complete after 1s Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
相關操作
通過定時備份計劃,查找備份。
通過
labelSelector
可以查找由備份計劃創建的備份。data "kubernetes_resources" "list-applicationbackup" { api_version = "csdr.alibabacloud.com/v1beta1" kind = "ApplicationBackup" namespace = "csdr" label_selector = "csdr/schedule-name=terraform-schedule-test" } # 通過Output進行輸出。 output "applicationbackup-name" { value = data.kubernetes_resources.list-applicationbackup.objects }
修改定時備份計劃。
將
spec.paused
設置為true
,以暫停定時備份計劃,然后根據需求修改spec
中用于設置備份計劃中定義備份行為的其他字段(spec.schedule
)等,示例如下。resource "kubernetes_manifest" "backupschedule-demo" { manifest = { apiVersion = "csdr.alibabacloud.com/v1beta1" kind = "BackupSchedule" metadata = { name = "<yourBackcupscheduleName>" namespace = "csdr" annotations = { "csdr.alibabacloud.com/backuplocations" = "{\"name\":\"<yourBackuplocationName>\",\"region\":\"cn-beijing\",\"bucket\":\"<cnfs-oss-yourBucketName>\",\"prefix\":\"<subDir>\",\"provider\":\"alibabacloud\"}" } } spec = { # 暫停備份計劃。 paused = "true" # 修改備份計劃的備份周期。 schedule = "0 5 * * *" template = { includedNamespaces = ["default","default1"] includedResources = ["statefulset"] excludedResources = ["excludedResources"] labelSelector = { matchLabels = { "app" = "mysql-sts" } } pvBackup = { defaultPvBackup = "false" } storageLocation = "vault-a" ttl = "720h0m0s" includeClusterResources = "false" } } } wait { fields = { # 暫停備份計劃后,預期的狀態應為Paused。 "status.phase" = "Paused" } } timeouts { create = "10m" } }
執行以下命令,生成資源規劃。
terraform plan
返回如下信息,表明資源規劃生成成功。
kubernetes_manifest.backupschedule-demo: Refreshing state... Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: ~ update in-place Terraform will perform the following actions: # kubernetes_manifest.backupschedule-demo will be updated in-place ~ resource "kubernetes_manifest" "backupschedule-demo" { ~ manifest = { ~ spec = { ~ paused = "false" -> "true" ~ schedule = "1 4 * * *" -> "0 5 * * *" # (1 unchanged attribute hidden) } # (3 unchanged attributes hidden) } ~ object = { ~ spec = { ~ paused = false -> true ~ schedule = "1 4 * * *" -> "0 5 * * *" # (2 unchanged attributes hidden) } # (3 unchanged attributes hidden) } ~ wait { ~ fields = { ~ "status.phase" = "Enabled" -> "Paused" } } # (1 unchanged block hidden) } Plan: 0 to add, 1 to change, 0 to destroy.
執行以下命令,使定時備份計劃修改生效。
terraform apply
返回信息如下,表明定時備份計劃修改成功。
kubernetes_manifest.backupschedule-demo: Modifying... kubernetes_manifest.backupschedule-demo: Modifications complete after 1s Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
步驟四:創建恢復任務
在csdr.tf配置文件中加入以下內容,并根據實際需求修改。
resource "kubernetes_manifest" "applicationrestore-demo" { manifest = { apiVersion = "csdr.alibabacloud.com/v1beta1" kind = "ApplicationRestore" metadata = { name = "<yourApplicationRestoreName>" namespace = "csdr" annotations = { "csdr.alibabacloud.com/backuplocations" = "{\"name\":\"<yourBackuplocationName>\",\"region\":\"cn-beijing\",\"bucket\":\"<cnfs-oss-yourBucketName>\",\"prefix\":\"<subDir>\",\"provider\":\"alibabacloud\"}" } } spec = { appRestoreOnly = "false" preserveNodePorts = "true" includedNamespaces = ["default","default1"] includedResources = ["statefulset"] excludedResources = ["excludedResources"] convertedarg = [ { convertToStorageClassType = "alicloud-disk-topology-alltype" namespace = "default" persistentVolumeClaim = "pvc-nas" }, { convertToStorageClassType = "alicloud-disk-topology-alltype" namespace = "default1" persistentVolumeClaim = "pvc-oss" } ] backupName = "<yourApplicationBackupName>" namespaceMapping = { "<backupNamespace>" = "<restoreNamespace>" } } } # 恢復成功完成的標志為status.phase轉化為Completed階段。 # 恢復時長與集群應用數量、存儲卷數據量有關。 #wait { # fields = { # "status.phase" = "Completed" # } #} #timeouts { # create = "60m" #} }
參數
是否必選
說明
csdr.alibabacloud.com/backuplocations
是
備份所在的備份倉庫信息,需與備份倉庫的配置一致。
name
是
恢復任務的名稱。
appRestoreOnly
否
對于備份了存儲卷的備份,是否僅恢復應用,不恢復存儲聲明、存儲卷及其對應的數據,取值:
true:僅恢復應用。如果您需要更改備份應用的數據源,可以先手動創建存儲聲明、存儲卷,然后再創建恢復任務并將該參數設置為true。
false:恢復應用以及相關的存儲數據,默認為false。
preserveNodePorts
否
是否保持應用的NodePort端口。當備份集群與恢復集群相同時,默認為false,將隨機修改端口值,避免與已有的同類應用沖突。否則設置為true。
includedNamespaces
是
指定恢復的命名空間名稱。設置為空時,表示恢復所有已備份的命名空間。
includedResources
否
指定待恢復的集群資源類型。
重要為避免非預期備份結果,includedResources和excludedResources您只需配置一項。均為空時,表示恢復所有已備份的資源類型。
excludedResources
否
排除待恢復的集群資源類型。
重要為避免非預期備份結果,includedResources和excludedResources您只需配置一項。均為空時,表示恢復所有已備份的資源類型。
backupName
是
待恢復的備份名稱。使用定期備份功能時,需要指定為某個時間點創建的備份名稱,例如<yourBackupScheduleName>-20221205225845。
namespaceMapping
否
重定義命名空間。取值:
<backupNamespace>:創建備份任務時指定的備份集群命名空間。
<restoreNamespace>:根據備份創建的資源在恢復集群的所在命名空間。若不設置,則默認在同名命名空間中恢復。
說明若<restoreNamespace>不存在,將創建新的命名空間。
convertedarg
否
轉換存儲類列表。備份中的FileSystem數據類型的存儲卷(OSS、NAS、CPFS、本地存儲等)的存儲聲明,在當前集群中恢復為目標存儲類,實現例如NAS存儲至云盤存儲的轉換。
convertToStorageClassType:目標存儲類,需要在當前集群已存在。當前版本僅支持選擇云盤或NAS類型的存儲類。
namespace:存儲聲明所在的命名空間。
persistentVolumeClaim:存儲聲明名稱。
您可以通過
kubectl -ncsdr describe <backup-name>
查詢備份的存儲聲明信息,在輸出的status.resourceList.dataResource.pvcBackupInfo
列表中dataType字段為數據類型,分為FileSystem與Snapshot,nameSpace與pvcName分別為存儲聲明所在的命名空間與存儲聲明名稱。執行以下命令,生成資源規劃。
terraform plan
返回信息如下,表明資源規劃生成成功。
# kubernetes_manifest.applicationrestore-demo will be created + resource "kubernetes_manifest" "applicationrestore-demo" { + manifest = { + apiVersion = "csdr.alibabacloud.com/v1beta1" + kind = "ApplicationRestore" + metadata = { + annotations = { + "csdr.alibabacloud.com/backuplocations" = "{name:<yourBackuplocationName>,region:cn-beijing,bucket:<cnfs-oss-yourBucketName>,prefix:subpath,provider:alibabacloud}" } + name = "<yourApplicationRestoreName>" + namespace = "csdr" } + spec = { + appRestoreOnly = "false" + backupName = "<yourApplicationbackupName>" + convertedarg = [ + { + convertToStorageClassType = "alicloud-disk-topology-alltype" + namespace = "default" + persistentVolumeClaim = "pvc-nas" }, + { + convertToStorageClassType = "alicloud-disk-topology-alltype" + namespace = "default1" + persistentVolumeClaim = "pvc-oss" }, ] + excludedResources = [ + "excludedResources", ] + includedNamespaces = [ + "default", + "default1", ] + includedResources = [ + "statefulset", ] + namespaceMapping = { + default = "default1" } + preserveNodePorts = "true" } } + object = { + apiVersion = "csdr.alibabacloud.com/v1beta1" + kind = "ApplicationRestore" + metadata = { + annotations = (known after apply) + creationTimestamp = (known after apply) + deletionGracePeriodSeconds = (known after apply) + deletionTimestamp = (known after apply) + finalizers = (known after apply) + generateName = (known after apply) + generation = (known after apply) + labels = (known after apply) + managedFields = (known after apply) + name = "<yourApplicationRestoreName>" + namespace = "csdr" + ownerReferences = (known after apply) + resourceVersion = (known after apply) + selfLink = (known after apply) + uid = (known after apply) } + spec = { + appRestoreOnly = false + backupName = "<yourApplicationbackupName>" + convertedarg = [ + { + convertToStorageClassType = "alicloud-disk-topology-alltype" + namespace = "default" + persistentVolumeClaim = "pvc-nas" }, + { + convertToStorageClassType = "alicloud-disk-topology-alltype" + namespace = "default1" + persistentVolumeClaim = "pvc-oss" }, ] + excludedNamespaces = (known after apply) + excludedResources = [ + "excludedResources", ] + existingResourcePolicy = (known after apply) + includeClusterResources = (known after apply) + includedNamespaces = [ + "default", + "default1", ] + includedResources = [ + "statefulset", ] + labelSelector = { + matchExpressions = (known after apply) + matchLabels = (known after apply) } + namespaceMapping = { + default = "default1" } + preserveNodePorts = true + pvRestore = { + pvcPrefix = (known after apply) + pvcSuffix = (known after apply) } + pvRestoreOnly = (known after apply) } } }
執行以下命令,創建恢復任務。
terraform apply
返回信息如下,表明恢復任務創建完成。
kubernetes_manifest.applicationbackup-demo: Creating... kubernetes_manifest.applicationrestore-demo: Creation complete after 1s Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
步驟五:刪除集群備份中心的相關資源
由于您已創建的備份倉庫可能正在被其他集群使用,所以備份中心不支持備份倉庫BackupLocation資源的刪除。
刪除定時備份計劃
您可以直接通過terraform destroy
刪除定時備份計劃BackupSchedule資源,停止定時備份。
刪除備份任務或恢復任務
在csdr.tf配置文件中加入以下內容,并根據實際需求修改。
resource "kubernetes_manifest" "deleterequest-demo" { manifest = { apiVersion = "csdr.alibabacloud.com/v1beta1" kind = "DeleteRequest" metadata = { name = "<objectName-dbr>" namespace = "csdr" } spec = { deleteObjectName = "<objectName>" deleteObjectType = "Backup" } } }
參數
是否必選
說明
name
是
刪除請求的名稱。
刪除備份任務時:待刪除的備份任務ApplicationBackup的名稱+“-dbr”。
刪除恢復任務時:待刪除的恢復任務ApplicationRestore的名稱+“-dbr”。
deleteObjectName
是
待刪除的資源名稱。
deleteObjectType
是
待刪除的資源類型。取值:
"Backup":刪除備份任務ApplicationBackup及配套資源。
"Restore":刪除恢復任務ApplicationRestore及配套資源。
說明刪除備份任務不會影響已同步到集群中的副本。
刪除恢復任務不會影響已恢復的內容。
執行以下命令,生成資源規劃。
terraform plan
返回信息如下,表明資源規劃生成成功。
# kubernetes_manifest.deleterequest-demo will be created + resource "kubernetes_manifest" "deleterequest-demo" { + manifest = { + apiVersion = "csdr.alibabacloud.com/v1beta1" + kind = "DeleteRequest" + metadata = { + name = "<objectName-dbr>" + namespace = "csdr" } + spec = { + deleteObjectName = "<objectName>" + deleteObjectType = "Backup" } } + object = { + apiVersion = "csdr.alibabacloud.com/v1beta1" + kind = "DeleteRequest" + metadata = { + annotations = (known after apply) + creationTimestamp = (known after apply) + deletionGracePeriodSeconds = (known after apply) + deletionTimestamp = (known after apply) + finalizers = (known after apply) + generateName = (known after apply) + generation = (known after apply) + labels = (known after apply) + managedFields = (known after apply) + name = "<objectName-dbr>" + namespace = "csdr" + ownerReferences = (known after apply) + resourceVersion = (known after apply) + selfLink = (known after apply) + uid = (known after apply) } + spec = { + backupName = (known after apply) + deleteObjectName = "<objectName>" + deleteObjectType = "Backup" } } }
執行以下命令,刪除資源。
terraform apply
返回信息如下,表明
deleterequest
資源刪除請求生效。kubernetes_manifest.deleterequest-demo: Creating... kubernetes_manifest.deleterequest-demo: Creation complete after 0s Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
說明系統根據
deleterequest
資源刪除請求,對應的備份或恢復任務刪除后,deleterequest
資源也會被刪除。
相關文檔
如需通過kubectl備份和恢復應用,請參見通過kubectl實現集群應用的備份和恢復。
如需通過容器服務控制臺備份和恢復應用,請參見如下文檔: