Skip to content

Instantly share code, notes, and snippets.

@ololx
Created October 25, 2023 07:19
Show Gist options
  • Save ololx/ffb86dbd5f11272710ed3a2336dd7533 to your computer and use it in GitHub Desktop.
Save ololx/ffb86dbd5f11272710ed3a2336dd7533 to your computer and use it in GitHub Desktop.
This is an sh script for the cloning cassandra keyspace
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage: $0 keyspace_from keyspace_to"
exit 1
fi
keyspace_from=$1
keyspace_to=$2
for src_table_dir in /data/cassandra/data/$keyspace_from/*-*
do
src_table=$(basename $src_table_dir)
table=$(echo $src_table | cut -d "-" -f 1)
if [ ! -d $src_table_dir/snapshots/clone ]; then
echo "NO SNAPSHOTS DIRECTORY IN $src_table_dir, SKIPPING..."
continue
fi
dest_table_dir=$(find /data/cassandra/data/$keyspace_to/ -maxdepth 1 -type d -name "$table-*")
if [ ! -d $dest_table_dir ]; then
echo "Destination table directory for $table does not exist in $keyspace_to, creating it..."
continue
fi
echo "Moving snapshots from $src_table_dir/snapshots to $dest_table_dir..."
for file in "$src_table_dir"/snapshots/clone/*; do
if [ -f "$file" ]; then
mv "$file" "$dest_table_dir/"
fi
done
mv $src_table_dir/snapshots/copy/* $dest_table_dir/
if [ $? -ne 0 ]; then
echo "Error during copying, exiting..."
exit 1
fi
done
echo "The clonning process done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment