Last active
July 3, 2017 19:00
-
-
Save pauloricardomg/10500655 to your computer and use it in GitHub Desktop.
Cassandra upgrade rollback sample script
This file contains hidden or 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 | |
set -e #fail on error | |
function log { | |
echo "[`date`] $@" | |
} | |
log "Rolling back cassandra. Press <ENTER> to continue.." | |
read | |
log "Stopping new cassandra version.." | |
/bin/ps -ef | /bin/grep -E "javaagent.*cassandra" | /bin/grep -v grep | /usr/bin/awk '{print $2}' | /usr/bin/xargs kill -9 | |
sleep 2 | |
DATA_DIR=/mnt/cassandra/data | |
OLD_DATA_DIR=/mnt/cassandra/data.old | |
for ks in `ls $DATA_DIR`; do | |
for cf in `ls $DATA_DIR/$ks`; do | |
log "Cleaning $ks/$cf" | |
mkdir -p $OLD_DATA_DIR/$ks/$cf | |
for file in `find $DATA_DIR/$ks/$cf -type f | grep -i -v snapshot | grep -v -i backup`; do | |
mv $file $OLD_DATA_DIR/$ks/$cf | |
done | |
log "Recovering $ks/$cf" | |
if [[ -d $DATA_DIR/$ks/$cf/snapshots/backup ]]; then | |
rsync -avhW --no-compress --progress $DATA_DIR/$ks/$cf/snapshots/backup/ $DATA_DIR/$ks/$cf; | |
fi | |
done | |
done | |
log "Starting old cassandra version.." | |
/opt/cassandra/bin/cassandra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment