Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scripts] Extend ceph.sh to use client.NAME instead of going for defaults #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions scripts/ceph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ 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.
trap -- 'trap - SIGINT SIGTERM SIGTSTP RETURN' RETURN
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."
Expand All @@ -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
Expand All @@ -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" \
Expand All @@ -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
Expand All @@ -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" \
Expand All @@ -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."
Expand All @@ -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
Expand Down