How to configure the rancher-backup operator to perform a Backup and Restore using local storage
如何配置牧场备份运营商使用本地存储执行备份和恢复

环境
服务联系WX:136-6258-1235

Rancher v2.5+  牧场主 v2.5+

Procedure  程序

The recommended method to configure the rancher-backup operator is to use S3 storage. This article explains how to use local storage only when S3 is not available, such as for Rancher migration between clusters or disaster recovery when the new cluster cannot access the original S3 backups.
配置 r-备份算子的推荐方法是  使用 S3 存储 。本文解释了仅在 S3 不可用时使用本地存储 ,例如集群间的牧场迁移或新集群无法访问原始 S3 备份时的灾难恢复。

Important: This setup is not recommended for production use. In production, backups should be stored in a persistent external location (such as S3) to ensure they are available externally in the event of a complete cluster failure.
重要提示: 这种配置不建议用于生产环境。在生产环境中,备份应存储在持久的外部位置(如 S3),以确保在集群完全崩溃时它们能在外部可用。

Backup Steps  备选步骤

  1. Create a hostPath PV in the Rancher local cluster using your desired local path (/backup in this example). The backup will be written only to the node running the rancher-backup pod at the time.
    在 Rancher 本地集群中创建一个 hostPath PV,使用你想要的本地路径(本例中为/backup)。备份仅写入当时运行 rancher-backup pod 的节点。
    <span style="background-color:#efefef"><code>apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: pv-rancher-backup
    spec:
      accessModes:
        - ReadWriteOnce
      capacity:
        storage: 3Gi
      hostPath:
        path: /backup
      persistentVolumeReclaimPolicy: Retain</code></span>
  2. Install the Rancher-backup operator, per the Rancher documentation. During installation, choose "Use an existing persistent volume" and select the PV created above in Step 1 as the default storage location.
    按照 Rancher 文档安装 Rancher 备份。安装时,选择“ 使用现有的持久卷 ”,并选择步骤 1 中创建的 PV 作为默认存储位置。
  3. Create a backup using the Rancher UI, per the rancher-backup operator documentation. Set the following options for the backup:
    根据牧场备份文档 ,使用 Rancher 界面创建备份。请为备份设置以下选项:
    • Schedule: One-Time Backup
      时间表:一次性备份
    • Resource Set: Full Rancher backup resource set
      资源集:完整牧场主备份资源集
    • Storage Location: Use the default storage location configured during installation.
      存储位置:使用安装时配置的默认存储位置。
    • Encryption: Store the contents of the backup unencrypted (or you can optionally configure encryption for the backup file as detailed in the documentation)
      加密:将备份内容未加密存储(或者你可以选择为备份文件配置加密,详见文档 

    Note: You might face the following error during the backup creation.
    注意:在备份创建过程中,您可能会遇到以下错误。

    <span style="background-color:#efefef"><code>Error creating backup tar gzip file: open /var/lib/backups/test-backup-3a869826-b3f6-4290-a083-78b801198d26-2026-01-22T09-45-33Z.tar.gz: permission denied</code></span>

    This error is due to a permission issue on the hostPath volume. The rancher-backup pod runs as UID 1000, so ensure the host directory (for example, /backup) is owned by UID 1000.
    此错误源于 hostPath 卷的权限问题。 牧场主备份舱运行为 UID 1000,确保主机目录(例如 /backup)归 UID 1000 所有。

  4. When the backup shows as completed, you can copy the backup file from the host path (e.g. /backup) directory on the node running the rancher-backup Pod.
    当备份显示已完成时,你可以从运行牧场备份 Pod 的节点的主机路径(例如/backup)目录复制备份文件。

Restore Steps  恢复台阶

  1. Copy your backup file onto all the nodes in the new cluster. This is to ensure that the backup-operator can find the file no matter where it is scheduled.
    把你的备份文件复制到新集群的所有节点上。这是为了确保备份无论文件被调度在哪里都能找到。
  2. Create a hostPath PV that mounts the directory where you copied your backup (/migration-backup in this example):
    创建一个 hostPath PV,挂载你复制备份的目录(本例中为/migration-backup):
    <span style="color:#181818">apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: migration
    spec:
      accessModes:
      - ReadWriteOnce
      capacity:
        storage: 10Gi
      hostPath:
        path: /migration-backup
        type: ""
      persistentVolumeReclaimPolicy: Retain
      volumeMode: Filesystem</span>
  3. Proceed with installing the Rancher Backup CRDs and charts by following section 1. Install the rancher-backup Helm chart from the rancher-backup operator documentation. Please note that in step 3. Install the charts, when installing the rancher-backup chart, you should edit the command to set the values persistence.enabled=true and persistence.volumeName=migration (adjusting the volumeName to match the PV created above in step 2.). For example:
    按照第 1 节安装 Rancher Backup CRD 和图表 。安装牧场主备份驾驶员文档中的 Helm 图表 。 请注意,在第三步。安装图表后,安装 rancher-backup 图表时,你应该编辑命令,设置 persistence.enabled=true 和 persistence.volumeName=migration(调整 volumeName 以匹配步骤 2 中创建的 PV)。例如:
    <span style="color:#181818">helm install rancher-backup rancher-charts/rancher-backup -n cattle-resources-system --version $CHART_VERSION --set persistence.enabled=true --set persistence.volumeName=migration</span>
  4. Confirm that the backup operator successfully mounted the hostPath PV and your backup is present
    确认备份成功安装了 hostPath PV,并且你的备份是否存在
    <span style="color:#181818">kubectl -n cattle-resources-system exec deploy/rancher-backup   -- ls /var/lib/backups </span>
  5. Create a Restore object. Update backupFilename to the name of the backup file copied in step 1. If the backup file is encrypted you will need to create the encryption secret in the cluster first and reference this in the encryptionConfigSecretName field of the Restore manifest spec.
    创建一个还原对象。将备份文件名更新为第一步复制的备份文件名称。如果备份文件是加密的,你需要先在集群中创建加密密钥 ,并在恢复清单规范的 encryptionConfigSecretName 字段中引用它。
    <span style="color:#181818"># restore-migration.yaml
    apiVersion: <a data-cke-saved-href="http://resources.cattle.io/v1" href="http://resources.cattle.io/v1">resources.cattle.io/v1</a>
    kind: Restore
    metadata:
      name: restore-migration
    spec:
      backupFilename: migration-adb5ba4a-ace3-4e53-878b-895170c9615c-2023-08-02T19-43-26Z.tar.gz
      prune: false</span>
  6. Apply the Restore object:
    应用恢复对象:
    <span style="color:#181818">kubectl apply -f restore-migration.yaml</span>
  7. Watch the restoration logs:
    观看修复日志:
    <span style="color:#181818">kubectl logs -n cattle-resources-system --tail 100 -f -l <a data-cke-saved-href="http://app.kubernetes.io/instance=rancher-backup" href="http://app.kubernetes.io/instance=rancher-backup">app.kubernetes.io/instance=rancher-backup</a></span>
  8. Continue with section 3. Install cert-manager onwards of the the rancher-backup operator migration documentation.
    继续阅读第 3 节。安装 cert-manager,支持 牧场主备份迁移文档 
Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐