10 find_target_table_name ()
15 find_in_dir=$dest_path/$keyspace_name
16 tname_without_uuid=$(echo $src_table_name | cut -d '-' -f 1)
17 dest_table_name=$(ls -td -- $find_in_dir/$tname_without_uuid-* | head -n 1 | rev | cut -d'/' -f1 | rev)
18 printf $dest_table_name
24 echo " Script to restore Cassandra database from Nuvo/Cain snapshot"
26 echo " $me [--help|-h] [--base_db_dir|-b] [--snapshot_dir|-s] [--keyspace|-k] [--tag|-t]"
27 echo " MUST OPTIONS: base_db_dir, snapshot_dir, keyspace_name"
29 echo " --base_db_dir, -b"
30 echo " Location of running Cassandra database"
31 echo " --snapshot_dir, -s"
32 echo " Snapshot location of Cassandra database taken by Nuvo/Cain"
33 echo " --keyspace, -k"
34 echo " Name of the keyspace to restore"
36 echo " $me -b /var/lib/cassandra/data -s /root/data.ss -k DISCOVERY_SERVER -t 1234567"
78 if [ "$base_db_dir" = "" ] || [ "$ss_dir" = "" ] || [ "$keyspace_name" = "" ]
81 echo ">>>>>>>>>>Not all inputs provided, please check usage >>>>>>>>>>"
86 # Remove commit logs from current data dir
87 #/var/lib/cassandra/commitlog/CommitLog*.log
88 find $base_db_dir/../ -name "CommitLog*.log" -delete
90 # Remove *.db from current data dir excluding skipped keyspaces
91 find $base_db_dir/$keyspace_name -name "*.db" -delete
93 # Copy snapshots to data dir
94 echo "----------db files in snapshots--------------"
95 dirs_to_be_restored=`ls $ss_dir`
96 for i in ${dirs_to_be_restored}
98 src_path=$ss_dir/$i/snapshots/$tag_name
99 # Find the destination
101 dest_table=$(find_target_table_name $base_db_dir $keyspace_name $table_name)
102 dest_path=$base_db_dir/$keyspace_name/$dest_table
103 # Create keyspace/table directory if not exists
104 #if [ ! -d "$dest_path" ]; then
105 # mkdir -p $dest_path
107 db_files=$(ls $src_path/*.db 2> /dev/null | wc -l)
108 if [ $db_files -ne 0 ]
110 cp $src_path/*.db $dest_path
113 echo "=====ERROR: Unable to restore $src_path/*.db to $dest_path====="
116 echo "=======check $dest_path ==============="