#!/usr/bin/env bash # Shared helpers for the host backup and host check scripts. Source only. # shellcheck shell=bash readonly HOST_BACKUP_ENV=/etc/platform-backup/aistor.env readonly TEXTFILE_DIR=/var/lib/node_exporter/textfile_collector # Backup staging (root 0700, same SSD). Not /var/tmp: dockerd must see the path. readonly HB_WORK_ROOT=/var/lib/platform-backup/work # Same pinned AIStor client as scripts/validate/aistor-s3-smoke.sh. readonly MC_IMAGE="quay.io/minio/aistor/mc@sha256:c5ec777c080fd6292b7529309a0f311c58c3a92e268c9c57c0901da86881949b" hb_log() { printf '%s %s\n' "$(date -u +%FT%TZ)" "$*"; } hb_fail() { hb_log "FAIL: $*" >&2; exit 1; } # Write Prometheus textfile metrics atomically: hb_write_metrics NAME <<'PROM' ... PROM hb_write_metrics() { local name="$1" tmp [[ -d "$TEXTFILE_DIR" ]] || { hb_log "textfile dir $TEXTFILE_DIR missing; metrics not written"; cat >/dev/null; return 0; } tmp="$(mktemp "$TEXTFILE_DIR/.${name}.XXXXXX")" cat >"$tmp" chmod 0644 "$tmp" mv -f -- "$tmp" "$TEXTFILE_DIR/${name}.prom" } # Load the AIStor endpoint and the backup user's keys (root-only file). hb_load_aistor_env() { [[ -f "$HOST_BACKUP_ENV" ]] || hb_fail "$HOST_BACKUP_ENV is missing; run scripts/bootstrap/create-host-backup-credentials.sh" [[ "$(stat -c '%u %a' "$HOST_BACKUP_ENV")" == "0 600" ]] || hb_fail "$HOST_BACKUP_ENV must be owned by root with mode 0600" # shellcheck disable=SC1090 . "$HOST_BACKUP_ENV" : "${AISTOR_BUCKET:?}" "${AISTOR_ACCESS_KEY:?}" "${AISTOR_SECRET_KEY:?}" # The host cannot resolve cluster DNS, so use the Service ClusterIP (port 80 -> 9000). if [[ -z "${AISTOR_ENDPOINT:-}" ]]; then local ip ip="$(/usr/local/bin/k3s kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml -n object-storage \ get service minio -o jsonpath='{.spec.clusterIP}')" [[ -n "$ip" ]] || hb_fail "cannot find the object-storage/minio Service" AISTOR_ENDPOINT="http://${ip}:80" fi } # Run the pinned mc client on the host network with the backup user's keys. # The keys go through a 0600 env file, never the command line (ps would show it). # Usage: hb_mc