From 522be17ea7aff4499c146dedc0e089a5f2856ecf Mon Sep 17 00:00:00 2001 From: "Eugenio A. Naselli" Date: Wed, 23 Aug 2023 12:22:17 +0200 Subject: [PATCH] Extend ceph.sh to use client.NAME instead of going for defaults --- scripts/ceph.sh | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/scripts/ceph.sh b/scripts/ceph.sh index b17c0e27..aa9e4492 100644 --- a/scripts/ceph.sh +++ b/scripts/ceph.sh @@ -14,6 +14,7 @@ function benji::backup::ceph::snapshot::create { local CEPH_POOL="$2" local CEPH_RBD_IMAGE="$3" local CEPH_RBD_SNAPSHOT="$4" + local CEPH_CLIENT="$5" # We need this to run through, so ignore termination and stop attempts for a time. # A trap for RETURN is not inherited by default, which is exactly what we need. @@ -21,7 +22,7 @@ function benji::backup::ceph::snapshot::create { trap -- '' SIGINT SIGTERM SIGTSTP # Start rbd with a timeout to increase the likelihood that we don't hang with signals off... - timeout --kill-after=10 30 rbd snap create "$CEPH_POOL"/"$CEPH_RBD_IMAGE"@"$CEPH_RBD_SNAPSHOT" + timeout --kill-after=10 30 rbd -n $CEPH_CLIENT snap create "$CEPH_POOL"/"$CEPH_RBD_IMAGE"@"$CEPH_RBD_SNAPSHOT" local EC=$? if [[ $EC == 124 ]]; then echo "Warning: Snapshot creation timed out for $CEPH_POOL/$CEPH_RBD_IMAGE." @@ -37,7 +38,8 @@ function benji::backup::ceph::initial { local VOLUME="$1" local CEPH_POOL="$2" local CEPH_RBD_IMAGE="$3" - shift 3 + local CEPH_CLIENT="$4" + shift 4 local VERSION_LABELS=("$@") local CEPH_RBD_SNAPSHOT="b-$(date '+%Y-%m-%dT%H:%M:%S')" # b-2017-04-19T11:33:23 @@ -48,9 +50,9 @@ function benji::backup::ceph::initial { echo "Performing initial backup of $VOLUME:$CEPH_POOL/$CEPH_RBD_IMAGE." - benji::backup::ceph::snapshot::create "$VOLUME" "$CEPH_POOL" "$CEPH_RBD_IMAGE" "$CEPH_RBD_SNAPSHOT" \ + benji::backup::ceph::snapshot::create "$VOLUME" "$CEPH_POOL" "$CEPH_RBD_IMAGE" "$CEPH_RBD_SNAPSHOT" "$CEPH_CLIENT" \ || return $? - rbd diff --whole-object "$CEPH_POOL"/"$CEPH_RBD_IMAGE"@"$CEPH_RBD_SNAPSHOT" --format=json >"$CEPH_RBD_DIFF_FILE" \ + rbd -n $CEPH_CLIENT diff --whole-object "$CEPH_POOL"/"$CEPH_RBD_IMAGE"@"$CEPH_RBD_SNAPSHOT" --format=json >"$CEPH_RBD_DIFF_FILE" \ || return $? VERSION_UID="$(benji -m --log-level "$BENJI_LOG_LEVEL" backup -s "$CEPH_RBD_SNAPSHOT" -r "$CEPH_RBD_DIFF_FILE" \ @@ -72,7 +74,8 @@ function benji::backup::ceph::differential { local CEPH_RBD_IMAGE="$3" local CEPH_RBD_SNAPSHOT_LAST="$4" local BENJI_VERSION_UID_LAST="$5" - shift 5 + local CEPH_CLIENT="$6" + shift 6 local VERSION_LABELS=("$@") local CEPH_RBD_SNAPSHOT="b-$(date '+%Y-%m-%dT%H:%M:%S')" # b-2017-04-20T11:33:23 @@ -84,12 +87,12 @@ function benji::backup::ceph::differential { echo "Performing differential backup of $VOLUME:$CEPH_POOL/$CEPH_RBD_IMAGE from RBD snapshot" \ "$CEPH_RBD_SNAPSHOT_LAST and Benji version $BENJI_VERSION_UID_LAST." - benji::backup::ceph::snapshot::create "$VOLUME" "$CEPH_POOL" "$CEPH_RBD_IMAGE" "$CEPH_RBD_SNAPSHOT" \ + benji::backup::ceph::snapshot::create "$VOLUME" "$CEPH_POOL" "$CEPH_RBD_IMAGE" "$CEPH_RBD_SNAPSHOT" "$CEPH_CLIENT" \ || return $? - rbd diff --whole-object "$CEPH_POOL"/"$CEPH_RBD_IMAGE"@"$CEPH_RBD_SNAPSHOT" --from-snap "$CEPH_RBD_SNAPSHOT_LAST" \ + rbd -n $CEPH_CLIENT diff --whole-object "$CEPH_POOL"/"$CEPH_RBD_IMAGE"@"$CEPH_RBD_SNAPSHOT" --from-snap "$CEPH_RBD_SNAPSHOT_LAST" \ --format=json >"$CEPH_RBD_DIFF_FILE" \ || return $? - rbd snap rm "$CEPH_POOL"/"$CEPH_RBD_IMAGE"@"$CEPH_RBD_SNAPSHOT_LAST" \ + rbd -n $CEPH_CLIENT snap rm "$CEPH_POOL"/"$CEPH_RBD_IMAGE"@"$CEPH_RBD_SNAPSHOT_LAST" \ || return $? VERSION_UID="$(benji -m --log-level "$BENJI_LOG_LEVEL" backup -s "$CEPH_RBD_SNAPSHOT" -r "$CEPH_RBD_DIFF_FILE" -f "$BENJI_VERSION_UID_LAST" \ @@ -106,16 +109,17 @@ function benji::backup::ceph { local VOLUME="$1" local CEPH_POOL="$2" local CEPH_RBD_IMAGE="$3" - shift 3 + local CEPH_CLIENT="$4" + shift 4 local VERSION_LABELS=("$@") # find the latest snapshot name from rbd - local CEPH_RBD_SNAPSHOT_LAST=$(rbd snap ls "$CEPH_POOL"/"$CEPH_RBD_IMAGE" --format=json | jq -r '[.[].name] | map(select(test("^b-"))) | sort | .[-1] // ""') + local CEPH_RBD_SNAPSHOT_LAST=$(rbd -n $CEPH_CLIENT snap ls "$CEPH_POOL"/"$CEPH_RBD_IMAGE" --format=json | jq -r '[.[].name] | map(select(test("^b-"))) | sort | .[-1] // ""') local EC=$?; [[ $EC == 0 ]] || return $EC if [[ ! $CEPH_RBD_SNAPSHOT_LAST ]]; then echo 'No previous RBD snapshot found, reverting to initial backup.' - benji::backup::ceph::initial "$VOLUME" "$CEPH_POOL" "$CEPH_RBD_IMAGE" "${VERSION_LABELS[@]}" + benji::backup::ceph::initial "$VOLUME" "$CEPH_POOL" "$CEPH_RBD_IMAGE" "$CEPH_CLIENT" "${VERSION_LABELS[@]}" EC=$? else echo "Snapshot found for $CEPH_POOL/$CEPH_RBD_IMAGE is $CEPH_RBD_SNAPSHOT_LAST." @@ -126,14 +130,14 @@ function benji::backup::ceph { if [[ $EC == 0 ]]; then if [[ ! $BENJI_SNAP_VERSION_UID ]]; then echo 'Existing RBD snapshot not found in Benji, deleting it and reverting to initial backup.' - rbd snap rm "$CEPH_POOL"/"$CEPH_RBD_IMAGE"@"$CEPH_RBD_SNAPSHOT_LAST" + rbd -n $CEPH_CLIENT snap rm "$CEPH_POOL"/"$CEPH_RBD_IMAGE"@"$CEPH_RBD_SNAPSHOT_LAST" EC=$? if [[ $EC == 0 ]]; then - benji::backup::ceph::initial "$VOLUME" "$CEPH_POOL" "$CEPH_RBD_IMAGE" "${VERSION_LABELS[@]}" + benji::backup::ceph::initial "$VOLUME" "$CEPH_POOL" "$CEPH_RBD_IMAGE" "$CEPH_CLIENT" "${VERSION_LABELS[@]}" EC=$? fi else - benji::backup::ceph::differential "$VOLUME" "$CEPH_POOL" "$CEPH_RBD_IMAGE" "$CEPH_RBD_SNAPSHOT_LAST" "$BENJI_SNAP_VERSION_UID" "${VERSION_LABELS[@]}" + benji::backup::ceph::differential "$VOLUME" "$CEPH_POOL" "$CEPH_RBD_IMAGE" "$CEPH_RBD_SNAPSHOT_LAST" "$BENJI_SNAP_VERSION_UID" "$CEPH_CLIENT" "${VERSION_LABELS[@]}" EC=$? fi fi