Skip to content

Instantly share code, notes, and snippets.

@mminer
Created November 26, 2018 20:56
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 mminer/5950d83218e0d3f9ceb151c648add7ed to your computer and use it in GitHub Desktop.
Save mminer/5950d83218e0d3f9ceb151c648add7ed to your computer and use it in GitHub Desktop.
Restores Docker volumes from tar archives.
#!/usr/bin/env bash
usage() {
cat <<EOF
Usage: $0 VOLUME [VOLUME ...]
Restore Docker volumes from tar archives.
EOF
}
if (( $# < 1 )); then
usage
exit 1
fi
for volume in "$@"; do
docker run --rm --volume=${volume}:/data --volume=$(pwd):/backup:ro ubuntu \
bash -c "cd /data && tar xf /backup/${volume}.tar --strip 1" \
&& echo "Restored volume ${volume} from ${volume}.tar"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment