Created
October 28, 2014 18:16
-
-
Save tobert/d3a047fa438bace6da1a 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