7.5. 执行备份


您可以使用 OpenShift CLI (oc)工具执行备份。

注意

以下示例 hello-world 应用没有附加的持久性卷。DPA 配置将正常工作。

流程

  1. 创建工作负载以备份:

    $ oc create namespace hello-world
    $ oc new-app -n hello-world --image=docker.io/openshift/hello-openshift
  2. 公开路由:

    $ oc expose service/hello-openshift -n hello-world
  3. 检查应用程序是否正常工作:

    $ curl `oc get route/hello-openshift -n hello-world -o jsonpath='{.spec.host}'`

    输出示例

    Hello OpenShift!

  4. 备份工作负载:

    $ cat << EOF | oc create -f -
    apiVersion: velero.io/v1
    kind: Backup
    metadata:
     name: hello-world
     namespace: openshift-adp
    spec:
     includedNamespaces:
     - hello-world
     storageLocation: ${CLUSTER_NAME}-dpa-1
     ttl: 720h0m0s
    EOF
  5. 等待备份完成:

    $ watch "oc -n openshift-adp get backup hello-world -o json | jq .status"

    输出示例

    {
     "completionTimestamp": "2022-09-07T22:20:44Z",
     "expiration": "2022-10-07T22:20:22Z",
     "formatVersion": "1.1.0",
     "phase": "Completed",
     "progress": {
       "itemsBackedUp": 58,
       "totalItems": 58
     },
     "startTimestamp": "2022-09-07T22:20:22Z",
     "version": 1
    }

  6. 删除演示工作负载:

    $ oc delete ns hello-world
  7. 从备份中恢复:

    $ cat << EOF | oc create -f -
    apiVersion: velero.io/v1
    kind: Restore
    metadata:
     name: hello-world
     namespace: openshift-adp
    spec:
     backupName: hello-world
    EOF
  8. 等待 Restore 完成:

    $ watch "oc -n openshift-adp get restore hello-world -o json | jq .status"

    输出示例

    {
     "completionTimestamp": "2022-09-07T22:25:47Z",
     "phase": "Completed",
     "progress": {
       "itemsRestored": 38,
       "totalItems": 38
     },
     "startTimestamp": "2022-09-07T22:25:28Z",
     "warnings": 9
    }

  9. 检查工作负载是否已恢复:

    $ oc -n hello-world get pods

    输出示例

    NAME                              READY   STATUS    RESTARTS   AGE
    hello-openshift-9f885f7c6-kdjpj   1/1     Running   0          90s

    $ curl `oc get route/hello-openshift -n hello-world -o jsonpath='{.spec.host}'`

    输出示例

    Hello OpenShift!

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部