Last active
December 6, 2016 09:49
-
-
Save iconara/32438720eeba8eb5659c2fc8df1f63bd to your computer and use it in GitHub Desktop.
Check Cassandra backup integrity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function log() { | |
logger -st "cbck[$$]" "$@" | |
} | |
function check_failed() { | |
log -p user.err "Check failed: $1" | |
exit 1 | |
} | |
function s3_exists() { | |
aws s3 ls "$1" > /dev/null | |
} | |
if [[ $# -lt 2 ]]; then | |
log -p user.err "Usage: $0 S3_URI KEYSPACE_NAME" | |
exit 2 | |
fi | |
uri="$1" | |
keyspace="$2" | |
log "Checking for $keyspace.cql" | |
if ! s3_exists "$uri/$keyspace.cql"; then | |
check_failed "$keyspace.cql not found" | |
fi | |
for table in $(aws s3 ls "$uri/" | perl -n -e 'm<PRE (.+)/> && print "$1\n"'); do | |
log "Checking table $table" | |
if ! s3_exists "$uri/$table/manifest.json"; then | |
check_failed "missing manifest for table $table" | |
fi | |
listing=$(aws s3 ls $uri/$table/ | awk '{print $4}') | |
prefixes=$(aws s3 cp "$uri/$table/manifest.json" - | jp 'files' | perl -n -e '/"(.+)-Data\.db"/ && print "$1\n"') | |
for prefix in $prefixes; do | |
log "Checking prefix $prefix in table $table" | |
if ! [[ $listing == *"$prefix-TOC.txt"* ]]; then | |
check_failed "missing file $prefix-TOC.txt for table $table" | |
fi | |
suffixes=$(aws s3 cp "$uri/$table/$prefix-TOC.txt" -) | |
for suffix in $suffixes; do | |
if ! [[ $listing == *"$prefix-$suffix"* ]]; then | |
check_failed "missing file $prefix-$suffix for table $table" | |
fi | |
done | |
done | |
done | |
log 'All ok' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment