Skip to content

Instantly share code, notes, and snippets.

@niclashoyer
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niclashoyer/9820571 to your computer and use it in GitHub Desktop.
Save niclashoyer/9820571 to your computer and use it in GitHub Desktop.
Simple docker backup
#!/bin/bash
set -e
set -u
CONTAINER=$(docker ps -a --no-trunc | awk 'NR>1' | awk 'BEGIN {FS=" +"}; $5 ~ "^Up" {print $1}')
for C in $CONTAINER; do
echo "Backup for $C"
DATA=$(docker inspect $C)
VOLS=$(echo "$DATA" | jq -r '.[0].Volumes|to_entries[].key' | tr '\n' ' ')
DESTVOL="$C""_volumes.tar.gz"
DESTINS="$C""_inspect.json"
CMD="tar czfP - $VOLS"
docker run --rm -i --volumes-from $C ubuntu $CMD > $DESTVOL
echo "$DATA" > $DESTINS
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment