diff --git a/README.md b/README.md index 9f8b8ed..0612be7 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ run a single service: open bash on server -* cassandra1: `docker exec -it cassandra1 /bin/bash ` +* cassandra1: `docker exec -it cassandra1 /bin/bash` * cassandra2: `docker exec -it cassandra2 /bin/bash` * cassandra3: `docker exec -it cassandra3 /bin/bash` diff --git a/dump.sh b/dump.sh index 702b86a..032cd7c 100755 --- a/dump.sh +++ b/dump.sh @@ -12,6 +12,9 @@ CQLSH="/home/alfredo.oliviero/apache-cassandra-4.1.3/bin/cqlsh" CQLSH_IP="10.1.28.100" DUMP_TAG="dump_docker" +NODE=cass-dev-01 +NODE_NAME=node1 + # Create directory for dumps mkdir -p $LOCAL_DIR @@ -37,10 +40,10 @@ snapshot_and_copy() { rm -rf $LOCAL_DIR/$NODE_NAME log "Removing old snapshots on $NODE" - ssh $SSH_USER@$NODE "$NODETOOL clearsnapshot -t $DUMP_TAG -- $KEYSPACE" + ssh $SSH_USER@$NODE "sudo $NODETOOL clearsnapshot -t $DUMP_TAG -- $KEYSPACE" log "Creating snapshot on $NODE" - ssh $SSH_USER@$NODE "$NODETOOL snapshot -t $DUMP_TAG $KEYSPACE" + ssh $SSH_USER@$NODE "sudo $NODETOOL snapshot -t $DUMP_TAG $KEYSPACE" # Find the snapshot path and copy it if it exists TABLES=$(ssh $SSH_USER@$NODE "find $SNAPSHOT_PATH -name $DUMP_TAG") @@ -50,10 +53,10 @@ snapshot_and_copy() { log ">> table path $TABLE_PATH\n>> table name $TABLE_NAME\n>> local table dir $LOCAL_TABLE_DIR; " - mkdir -p $LOCAL_TABLE_DIR/snapshots/$KEYSPACE + mkdir -p $LOCAL_TABLE_DIR log "Copying snapshot from $NODE:$TABLE_PATH to $LOCAL_TABLE_DIR/$DUMP_TAG" - rsync -C -r $SSH_USER@$NODE:$TABLE_PATH/ $LOCAL_TABLE_DIR/snapshots/$KEYSPACE + rsync -C -r $SSH_USER@$NODE:$TABLE_PATH/ $LOCAL_TABLE_DIR/ done } @@ -73,7 +76,7 @@ log "Starting snapshot creation for keyspace $KEYSPACE" log "Exporting keyspace schema for $KEYSPACE from ${NODES[0]}" mkdir -p ${LOCAL_DIR}/schema -ssh $SSH_USER@${NODES[0]} "$CQLSH $CQLSH_IP -e 'DESCRIBE KEYSPACE $KEYSPACE;'" > "${LOCAL_DIR}/schema/${KEYSPACE}_schema.cql" +ssh $SSH_USER@${NODES[0]} "sudo $CQLSH $CQLSH_IP -e 'DESCRIBE KEYSPACE $KEYSPACE;'" > "${LOCAL_DIR}/schema/${KEYSPACE}_schema.cql" # Perform snapshot and copy for each node in parallel NODE_INDEX=1 diff --git a/scripts/setup.sh b/scripts/setup.sh index 826dec4..1b443fd 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -12,7 +12,7 @@ KEYSPACE="dev_keyspace_1" DUMP_DIR="/dump" # Ensure DUMP_DIR is defined SNAPSHOT_DIR="$DUMP_DIR/snapshot" # Ensure DUMP_DIR is defined SCHEMA_PATH="$DUMP_DIR/schema/${KEYSPACE}_schema.cql" # Ensure DUMP_DIR is defined -DUMP_TAG="dump_docker" +DUMP_TAG="dev_keyspace_1" # Determine the IP address of the current node IP_ADDRESS=$(hostname -I | awk '{print $1}') @@ -38,31 +38,6 @@ done # Log the value of PRIMARY_NODE for debugging log "PRIMARY_NODE is set to: $PRIMARY_NODE" -if [ "$PRIMARY_NODE" = "true" ]; then - # Check if the keyspace exists - log "Checking if keyspace $KEYSPACE exists..." - if ! cqlsh $IP_ADDRESS -e "DESCRIBE KEYSPACE $KEYSPACE;" > /dev/null 2>&1; then - log "Keyspace $KEYSPACE does not exist. Creating keyspace and tables..." - cqlsh $IP_ADDRESS -f $SCHEMA_PATH - else - log "Keyspace $KEYSPACE already exists. Ensuring tables exist..." - fi -else - log "This is not the primary node. Skipping keyspace and table creation." -fi - -# Import snapshots using sstableloader -log "Importing snapshots using sstableloader..." -for TABLE_DIR in $(ls $SNAPSHOT_DIR); do - TABLE_NAME=$(basename $TABLE_DIR) # Extract table name from directory name - echo "Importing table: $TABLE_NAME from directory: $TABLE_DIR" - echo "Command: sstableloader -d $CASSANDRA_SEEDS $SNAPSHOT_DIR/$TABLE_DIR" - # sstableloader -d $CASSANDRA_SEEDS $SNAPSHOT_DIR/$TABLE_DIR -ks $KEYSPACE - nodetool import -- $KEYSPACE $TABLE_NAME $SNAPSHOT_DIR/$TABLE_DIR/snapshots/$KEYSPACE - cqlsh $IP_ADDRESS -k $KEYSPACE -e "select count(*) from $TABLE_NAME;" >&2 -done - -log "FINISHED IMPORT" # Keep the container running tail -f /dev/null