#!/bin/bash KEYSPACES=`cqlsh 10.2.32.23 -u cassandra -p cassandra -e "DESCRIBE KEYSPACES"` TABLE_LIST=`nodetool cfstats | grep "Table: " | sed -e 's+^.*: ++'` for KEYSPACE in $KEYSPACES; do if [ "$KEYSPACE" = "system" ]; then echo ------------------SYSTEM KEYSPACE ${KEYSPACE}: SKIPPING--------------------------- continue fi if [ "$KEYSPACE" = "system_traces" ]; then echo ------------------SYSTEM KEYSPACE ${KEYSPACE}: SKIPPING--------------------------- continue fi echo "-------------------Restoring: ${KEYSPACE}-------------------------" echo "Tables to restore:" TABLE_LIST=`cqlsh 10.2.32.23 -u cassandra -p cassandra -e "DESCRIBE KEYSPACE ${KEYSPACE}" | grep "CREATE TABLE" | sed -e 's+CREATE TABLE++' | sed -e 's+(++'` echo $TABLE_LIST for table in $TABLE_LIST; do if [ ! -d "${1}var/lib/cassandra/data/${KEYSPACE}/${table}/snapshots/${2}" ]; then echo SKIP "${1}var/lib/cassandra/data/${KEYSPACE}/${table}/snapshots/${2}"; else echo START COPY ${1}/var/lib/cassandra/data/${KEYSPACE}/${table}/snapshots/${2} sudo cp -a "${1}var/lib/cassandra/data/${KEYSPACE}/${table}/snapshots/${2}/." "/var/lib/cassandra/data/${KEYSPACE}/${table}/" echo COPIED TO /var/lib/cassandra/data/${KEYSPACE}/${table} sudo chown -R cassandra /var/lib/cassandra/data/${KEYSPACE}/${table} sudo nodetool refresh -- ${KEYSPACE} ${table} echo NODE TOOL SUCCESS fi done echo "Resotred: ${KEYSPACE}----------------" done