Skip to content

Instantly share code, notes, and snippets.

@rdemoraes
Created April 13, 2021 16:03
Show Gist options
  • Select an option

  • Save rdemoraes/98e077712a38be78f4b10e3e68c28c80 to your computer and use it in GitHub Desktop.

Select an option

Save rdemoraes/98e077712a38be78f4b10e3e68c28c80 to your computer and use it in GitHub Desktop.
Script for Cassandra's backup
#!/bin/bash
set -euif [[ -z "$1" ]]; then
info "Please provide a keyspace"
exit 1
fiKEYSPACE="$1"
result=$(nodetool snapshot "${KEYSPACE}")
if [[ $? -ne 0 ]]; then
echo "Error while making snapshot"
exit 1
fitimestamp=$(echo "$result" | awk '/Snapshot directory: / { print $3 }')mkdir -p /tmp/backupfor path in $(find "/var/lib/cassandra/data/${KEYSPACE}" -name $timestamp); do
table=$(echo "${path}" | awk -F "[/-]" '{print $7}')
mkdir /tmp/backup/$table
mv $path /tmp/backup/$table
donetar -zcf /tmp/backup.tar.gz -C /tmp/backup .nodetool clearsnapshot "${KEYSPACE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment