Skip to content

Instantly share code, notes, and snippets.

@mheler
Forked from ZiggyMaes/radosgw-gc-bucket-indexes.sh
Created September 8, 2022 19:21
Show Gist options
  • Save mheler/2d6cc25fbeff0a811f324d215c00511f to your computer and use it in GitHub Desktop.
Save mheler/2d6cc25fbeff0a811f324d215c00511f to your computer and use it in GitHub Desktop.
Ceph RADOS Gateway bucket index garbage collection
#!/bin/bash
#
# Find orphaned bucket index objects in the RGW bucket index pool
# and clean them up if they do not belong to a bucket
#
# Author: Wido den Hollander <[email protected]>
#
INDEX_POOL=$1
if [ -z "$INDEX_POOL" ]; then
echo "Usage: $0 <index pool>"
exit 1
fi
INDEXES=$(mktemp)
METADATA=$(mktemp)
trap "rm -f ${INDEXES} ${METADATA}" EXIT
radosgw-admin metadata list bucket.instance|jq -r '.[]' > ${METADATA}
rados -p ${INDEX_POOL} ls > $INDEXES
for OBJECT in $(cat ${INDEXES}); do
MARKER=$(echo ${OBJECT}|cut -d '.' -f 3,4,5)
grep ${MARKER} ${METADATA} > /dev/null
if [ "$?" -ne 0 ]; then
echo $OBJECT
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment