Files
cozystack/examples/backups/nats/02-create-backupclass.sh
T
Timofei Larkin 727343d259 docs(backups): add NATS Job-strategy example
Add examples/backups/nats/, the first worked example of the generic Job
backup strategy. It backs up a NATS JetStream stream that has no dedicated
driver, using a stock natsio/nats-box image: 'nats stream backup' -> tar ->
curl --aws-sigv4 PUT to the COSI/seaweedfs S3 endpoint, and the reverse for
restore. One PodTemplateSpec serves both directions, branching at runtime on
{{ .Mode }} (the engine templates each string leaf independently and cannot
restructure the Pod per mode).

Mirrors the clickhouse example's structure: numbered scripts (bucket -> NATS
src + seeded stream -> strategy -> BackupClass -> BackupJob -> in-place and
to-copy RestoreJob), shared helpers, run-all.sh, README, and scenario docs.
Like every examples/backups/* dir it is a runnable demo, not CI-gated.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
2026-05-26 18:06:37 +03:00

36 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# Step 02: Map the NATS application kind to the Job strategy from step 01. The
# strategy parameters (which stream to back up, which NATS user to connect as)
# travel through the BackupClass and are exposed to the strategy template as
# `.Parameters`. They are also snapshotted onto the resulting Backup's
# driverMetadata, so a later restore re-renders with the same values.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/00-helpers.sh"
print_header "Step 02: Create BackupClass '${BACKUPCLASS_NAME}'"
log_command "kubectl apply -f - (BackupClass: $BACKUPCLASS_NAME -> $STRATEGY_NAME)"
kubectl apply -f - <<EOF
apiVersion: backups.cozystack.io/v1alpha1
kind: BackupClass
metadata:
name: ${BACKUPCLASS_NAME}
spec:
strategies:
- application:
apiGroup: apps.cozystack.io
kind: NATS
strategyRef:
apiGroup: strategy.backups.cozystack.io
kind: Job
name: ${STRATEGY_NAME}
parameters:
stream: "${STREAM_NAME}"
natsUser: "${NATS_USER}"
EOF
log_success "BackupClass '${BACKUPCLASS_NAME}' created."
echo -e "\n${GREEN}${BOLD}Next:${NC} ./03-create-bucket.sh"