Created
October 25, 2023 07:19
-
-
Save ololx/ffb86dbd5f11272710ed3a2336dd7533 to your computer and use it in GitHub Desktop.
This is an sh script for the cloning cassandra keyspace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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