66 lines
2.0 KiB
Bash
Executable File
66 lines
2.0 KiB
Bash
Executable File
```sh
|
|
#!/bin/bash
|
|
|
|
# Configuration
|
|
KEYSPACE="dev_keyspace"
|
|
LOCAL_DIR="data/dumps"
|
|
NODES=("cass-dev-01" "cass-dev-02" "cass-dev-03")
|
|
SSH_USER="alfredo.oliviero"
|
|
SNAPSHOT_PATH="/data/$KEYSPACE"
|
|
NODETOOL="/home/alfredo.oliviero/apache-cassandra-4.1.3/bin/nodetool"
|
|
CQLSH="/home/alfredo.oliviero/apache-cassandra-4.1.3/bin/cqlsh"
|
|
CQLSH_IP="10.1.28.100"
|
|
|
|
# Function to create snapshot and copy it locally
|
|
snapshot_and_copy() {
|
|
NODE=$1
|
|
NODE_NAME=$2
|
|
echo "Removing old snapshots on $NODE"
|
|
ssh $SSH_USER@$NODE "$NODETOOL clearsnapshot --all -- $KEYSPACE"
|
|
|
|
echo "Creating snapshot on $NODE"
|
|
ssh $SSH_USER@$NODE "$NODETOOL snapshot $KEYSPACE"
|
|
|
|
# Find the snapshot path and copy it if it exists
|
|
TABLES=$(ssh $SSH_USER@$NODE "ls $SNAPSHOT_PATH")
|
|
rm -rf $LOCAL_DIR/$NODE_NAME
|
|
for TABLE in $TABLES; do
|
|
SNAPSHOT_DIR="$SNAPSHOT_PATH/$TABLE/snapshots"
|
|
if ssh $SSH_USER@$NODE "test -d $SNAPSHOT_DIR"; then
|
|
echo "Copying snapshot for table $TABLE from $NODE to $LOCAL_DIR/$NODE_NAME/$TABLE"
|
|
mkdir -p $LOCAL_DIR/$NODE_NAME/$TABLE
|
|
rsync -C -r $SSH_USER@$NODE:$SNAPSHOT_DIR/ $LOCAL_DIR/$NODE_NAME/$TABLE
|
|
else
|
|
echo "No snapshot found for table $TABLE on $NODE"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Export keyspace schema from the first node
|
|
echo "Exporting keyspace schema for $KEYSPACE from ${NODES[0]}"
|
|
ssh $SSH_USER@${NODES[0]} "$CQLSH $CQLSH_IP -e \"DESCRIBE KEYSPACE $KEYSPACE;\"" > data/dev_keyspace_schema.cql
|
|
|
|
# Create local directory if it doesn't exist
|
|
mkdir -p $LOCAL_DIR
|
|
|
|
# Perform snapshot and copy for each node in parallel
|
|
NODE_INDEX=1
|
|
for NODE in "${NODES[@]}"; do
|
|
snapshot_and_copy $NODE "node$NODE_INDEX" &
|
|
NODE_INDEX=$((NODE_INDEX + 1))
|
|
done
|
|
|
|
# Wait for all background jobs to finish
|
|
wait
|
|
|
|
echo "Backup completed."
|
|
|
|
# Display sizes of dumps
|
|
echo "Total size of each node dump directory:"
|
|
du -sh data/dumps/node1
|
|
du -sh data/dumps/node2
|
|
du -sh data/dumps/node3
|
|
|
|
echo "Total size of all dump directories:"
|
|
du -sh data/dumps/*
|