Skip to main content

CLI Usage

DR-Syncer provides a command-line interface (CLI) that allows you to perform disaster recovery operations directly from the command line without needing to deploy the controller.

Installation​

The CLI binary is built alongside the controller binary:

make build

This will create both the dr-syncer and dr-syncer-cli binaries in the bin/ directory.

Command-Line Flags​

FlagDescriptionRequired
--source-kubeconfigPath to the source cluster kubeconfig fileYes
--dest-kubeconfigPath to the destination cluster kubeconfig fileYes
--source-namespaceNamespace in the source clusterYes
--dest-namespaceNamespace in the destination clusterYes
--modeOperation mode: Stage, Cutover, or FailbackYes
--include-custom-resourcesInclude custom resources in synchronizationNo (default: false)
--migrate-pvc-dataMigrate PVC data using pv-migrateNo (default: false)
--reverse-migrate-pvc-dataMigrate PVC data from destination back to source (for Failback mode)No (default: false)
--pv-migrate-flagsAdditional flags to pass to pv-migrate (e.g. "--strategy rsync --lbsvc-timeout 10m")No (default: none)
--resource-typesComma-separated list of resource types to include (overrides defaults)No
--exclude-resource-typesComma-separated list of resource types to excludeNo
--log-levelLog level: debug, info, warn, errorNo (default: info)

Operation Modes​

Stage Mode​

In Stage mode, the CLI:

  1. Synchronizes resources from source to destination namespace
  2. Scales down deployments in the destination namespace to 0 replicas
  3. Optionally migrates PVC data if enabled

This mode is useful for preparing a disaster recovery environment without activating it.

bin/dr-syncer-cli \
--source-kubeconfig=/path/to/source/kubeconfig \
--dest-kubeconfig=/path/to/destination/kubeconfig \
--source-namespace=my-namespace \
--dest-namespace=my-namespace-dr \
--mode=Stage

Cutover Mode​

In Cutover mode, the CLI:

  1. Synchronizes resources from source to destination namespace
  2. Preserves original replica counts by annotating source deployments
  3. Scales down deployments in the source namespace to 0 replicas
  4. Scales up deployments in the destination namespace to the original replica counts
  5. Optionally migrates PVC data if enabled

This mode is used to perform an actual disaster recovery cutover.

bin/dr-syncer-cli \
--source-kubeconfig=/path/to/source/kubeconfig \
--dest-kubeconfig=/path/to/destination/kubeconfig \
--source-namespace=my-namespace \
--dest-namespace=my-namespace-dr \
--mode=Cutover

Failback Mode​

In Failback mode, the CLI:

  1. Optionally migrates PVC data from destination back to source (if reverse-migrate-pvc-data is set)
  2. Scales down deployments in the destination namespace to 0 replicas
  3. Scales up deployments in the source namespace to their original replica counts

This mode is used to return to the original source environment after a DR event.

bin/dr-syncer-cli \
--source-kubeconfig=/path/to/source/kubeconfig \
--dest-kubeconfig=/path/to/destination/kubeconfig \
--source-namespace=my-namespace \
--dest-namespace=my-namespace-dr \
--mode=Failback \
--reverse-migrate-pvc-data=true

Resource Types​

By default, the CLI synchronizes these standard Kubernetes resources:

  • ConfigMaps
  • Secrets
  • Deployments
  • StatefulSets
  • DaemonSets
  • Services
  • Ingresses
  • ServiceAccounts
  • Roles
  • RoleBindings
  • PersistentVolumeClaims
  • HorizontalPodAutoscalers
  • NetworkPolicies

Including Custom Resources​

To include custom resources in synchronization:

bin/dr-syncer-cli \
--source-kubeconfig=/path/to/source/kubeconfig \
--dest-kubeconfig=/path/to/destination/kubeconfig \
--source-namespace=my-namespace \
--dest-namespace=my-namespace-dr \
--mode=Stage \
--include-custom-resources=true

Specifying Specific Resource Types​

To synchronize only specific resource types:

bin/dr-syncer-cli \
--source-kubeconfig=/path/to/source/kubeconfig \
--dest-kubeconfig=/path/to/destination/kubeconfig \
--source-namespace=my-namespace \
--dest-namespace=my-namespace-dr \
--mode=Stage \
--resource-types=configmaps,secrets,deployments

Excluding Resource Types​

To exclude specific resource types:

bin/dr-syncer-cli \
--source-kubeconfig=/path/to/source/kubeconfig \
--dest-kubeconfig=/path/to/destination/kubeconfig \
--source-namespace=my-namespace \
--dest-namespace=my-namespace-dr \
--mode=Stage \
--exclude-resource-types=ingresses,networkpolicies

PVC Data Migration​

The CLI supports migrating data from source PVCs to destination PVCs using pv-migrate.

Requirements​

  • pv-migrate must be installed and available in your PATH
  • PVCs must exist in both source and destination namespaces

Usage​

bin/dr-syncer-cli \
--source-kubeconfig=/path/to/source/kubeconfig \
--dest-kubeconfig=/path/to/destination/kubeconfig \
--source-namespace=my-namespace \
--dest-namespace=my-namespace-dr \
--mode=Stage \
--migrate-pvc-data=true

Passing Additional Flags to pv-migrate​

You can pass additional flags directly to pv-migrate for more control over the migration process:

bin/dr-syncer-cli \
--source-kubeconfig=/path/to/source/kubeconfig \
--dest-kubeconfig=/path/to/destination/kubeconfig \
--source-namespace=my-namespace \
--dest-namespace=my-namespace-dr \
--mode=Stage \
--migrate-pvc-data=true \
--pv-migrate-flags="--lbsvc-timeout 10m --strategy rsync"

Common pv-migrate flags include:

  • --lbsvc-timeout: Timeout for load balancer service creation (default: 3m)
  • --strategy: Migration strategy to use (rsync, svc, or mnt2)
  • --rsync-opts: Additional rsync options
  • --no-cleanup-on-failure: Do not clean up temporary resources on failure

For failback:

bin/dr-syncer-cli \
--source-kubeconfig=/path/to/source/kubeconfig \
--dest-kubeconfig=/path/to/destination/kubeconfig \
--source-namespace=my-namespace \
--dest-namespace=my-namespace-dr \
--mode=Failback \
--reverse-migrate-pvc-data=true \
--pv-migrate-flags="--lbsvc-timeout 10m"