VolSync and Volume Backup

Relevant source files

The volume backup architecture in this repository provides a multi-tier data protection strategy. It leverages the VolSync operator to manage asynchronous replication of persistent volumes, utilizing Kopia for incremental, deduplicated backups to local NFS storage and off-site replication to Cloudflare R2. The system is built upon a foundation of local-path storage with snapshot capabilities provided by democratic-csi and the snapshot-controller.

Storage Foundation and Snapshots

Data persistence for most applications is handled by the local-hostpath StorageClass, which provides high-performance local storage while maintaining the ability to take volume snapshots.

Data Flow: Application to Snapshot

Sources: kubernetes/apps/storage/democratic-csi/app/helmrelease.yaml34-52kubernetes/apps/volsync-system/snapshot-controller/app/helmrelease.yaml1-53

VolSync Implementation

The VolSync operator is the core orchestration engine for backups. It is deployed using a fork (ghcr.io/perfectra1n/volsync) that supports specific enhancements for the home-ops environment kubernetes/apps/volsync-system/volsync/app/helmrelease.yaml26-29

Kustomize Components

To simplify the addition of backups to applications, a set of reusable Kustomize components is provided in kubernetes/components/volsync/kubernetes/components/volsync/kustomization.yaml1-10

  1. kopia.yaml: Configures the ReplicationSource for local backups.
  1. r2.yaml: (Implicitly referenced) Handles off-site replication to Cloudflare R2 object storage for disaster recovery.
  2. pvc.yaml: Manages the underlying persistent volume claims required by the VolSync movers.

Secret Management

VolSync requires repository passwords to encrypt Kopia data. These are managed via ExternalSecrets that pull kopia_password from Bitwarden kubernetes/components/volsync/kopia.yaml2-24

Sources: kubernetes/components/volsync/kopia.yaml1-99kubernetes/apps/volsync-system/volsync/app/helmrelease.yaml15-43

Backup Architecture

The backup process bridges the local Kubernetes environment with external storage targets.

Code-to-System Mapping

System ComponentCode Entity / CRDConfiguration File
Backup SourceReplicationSourcekubernetes/components/volsync/kopia.yaml65-68
Restore TargetReplicationDestinationkubernetes/components/volsync/kopia.yaml28-30
Storage TargetmoverVolumes (NFS)kubernetes/components/volsync/kopia.yaml82-87
Backup Enginekopiakubernetes/apps/volsync-system/volsync/app/helmrelease.yaml30
Secret TemplateExternalSecretkubernetes/components/volsync/kopia.yaml3-24

Multi-Tier Data Flow

Sources: kubernetes/components/volsync/kopia.yaml26-99kubernetes/apps/volsync-system/kopia/app/helmrelease.yaml88-128

Restore Operations

Restoration is handled through the ReplicationDestination resource, which defines how to pull data from the Kopia repository back into a PVC.

Taskfile Commands

Operational tasks for VolSync are automated via Taskfiles located in .taskfiles/VolSync/. These commands allow for manual intervention and disaster recovery:

  • List Snapshots: Uses .taskfiles/VolSync/resources/list-snapshots.yaml.j2 to query available recovery points in the Kopia repository.
  • Unlock Repository: Uses .taskfiles/VolSync/resources/unlock.yaml.j2 to clear stale locks from the backup repository.
  • Manual Restore: Deploys the ReplicationDestination CRD using templates like .taskfiles/VolSync/resources/replicationdestination.yaml.j2 to trigger a data pull.

System Maintenance and Security

Sources: kubernetes/apps/volsync-system/volsync/app/helmrelease.yaml39-42kubernetes/components/volsync/kopia.yaml54-57kubernetes/apps/volsync-system/volsync/maintenance/kopiamaintenance.yaml