-
-
Save rodneytamblyn/9ef464da1ff87f8fad4c8c5956064b47 to your computer and use it in GitHub Desktop.
Quick & dirty cassandra-in-docker backup script
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 | |
# A quick & dirty backup script for Cassandra running inside Docker. | |
# Assumes /var/lib/cassandra is mounted in the container as /var/lib/cassandra because | |
# docker inspect {{ .Volumes }} is not shell-friendly. (doable, but meh) | |
# Also assumes Cassandra was started with 'docker run --name cassandra'. | |
export PATH=$PATH:/home/atobey/bin:/usr/local/bin | |
set -e | |
ks="ccfp" | |
bucket="atobey-app-backups" | |
datadir="/var/lib/cassandra/data/${ks}" | |
name=$(date -Iminutes |sed 's/:/-/g') | |
tarball_file="/var/lib/cassandra/backups/${ks}-${name}.tar.gz" | |
ip=$(sudo docker inspect -f '{{ .NetworkSettings.IPAddress }}' cassandra) | |
nodetool --host $ip flush $ks | |
nodetool --host $ip snapshot $ks -t $name | |
sudo docker exec cassandra tar -czf $tarball_file $datadir/*/snapshots/$name | |
# assume /var/lib/cassandra is the volume in the container (for now) | |
if [ $? -eq 0 ] ; then | |
aws put "${bucket}/${tarball_file}" $tarball_file | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment