Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rodneytamblyn/9ef464da1ff87f8fad4c8c5956064b47 to your computer and use it in GitHub Desktop.
Save rodneytamblyn/9ef464da1ff87f8fad4c8c5956064b47 to your computer and use it in GitHub Desktop.
Quick & dirty cassandra-in-docker backup script
#!/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