Created
October 19, 2018 07:14
-
-
Save kamikat/5211a0512eed3a1bc63f5b41de1fad68 to your computer and use it in GitHub Desktop.
Backup & restore a local volume from docker.
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/sh | |
BUSYBOX_IMAGE=${BUSYBOX_IMAGE:-busybox} | |
BUSYBOX_IMAGE_ID=$(docker images -q $BUSYBOX_IMAGE | head -n1) | |
check_busybox() { | |
if [ -z "$BUSYBOX_IMAGE_ID" ]; then | |
echo >&2 "error: $BUSYBOX_IMAGE image not found." | |
exit 1 | |
fi | |
} | |
case "$1" in | |
export) | |
check_busybox | |
docker run --rm -v $2:/_data:ro $BUSYBOX_IMAGE_ID tar c -zf - -C / _data > $2.tar.gz | |
;; | |
import) | |
check_busybox | |
docker volume create $2 | |
docker run --rm -i -v $2:/_data:rw $BUSYBOX_IMAGE_ID tar x -zf - -C / < $3 | |
;; | |
*) | |
echo >&2 "usage: $0 export <volume-name>" | |
echo >&2 " $0 import <volume-name> <volume-file>" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment