Skip to content

Instantly share code, notes, and snippets.

@niclashoyer niclashoyer/backup.sh
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.