Created
January 31, 2021 22:50
-
-
Save pirafrank/e95c3e4eadd88756d96fa04cdfbf46f4 to your computer and use it in GitHub Desktop.
scripts to dump docker volume to a tar.gz file and import from it
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/bash | |
if [ $# -ne 2 ]; then | |
echo "Usage: ./$0 tar_archive_name volume_name" | |
exit 1 | |
fi | |
tararchive="$1" | |
volname="$2" | |
BASEDIR="$HOME/docker_vol_exports" | |
mkdir -p "$BASEDIR" | |
if [[ -f " $BASEDIR/$tararchive" ]]; then | |
echo 'removing old export' | |
rm -rf "$BASEDIR/$tararchive" | |
fi | |
echo 'creating new dir' | |
mkdir -p $BASEDIR | |
echo 'exporting data to tar archive' | |
src="$volname" | |
dest="$BASEDIR" | |
docker run --rm -it \ | |
-v $src:/from \ | |
-v $dest:/to \ | |
alpine ash -c "cd /from ; tar -czf /to/$tararchive ." | |
echo "Volume $volname has been exported to $BASEDIR" | |
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/bash | |
if [ $# -ne 2 ]; then | |
echo "Usage: ./$0 tar_archive_name volume_name" | |
exit 1 | |
fi | |
tararchive="$1" | |
volname="$2" | |
docker volume rm $volname | |
docker volume create $volname | |
src="$(pwd)" | |
dest="$volname" | |
docker run --rm -it \ | |
-v $src:/from \ | |
-v $dest:/to \ | |
alpine ash -c "cd /from ; tar -xzf $tararchive -C /to/" | |
echo "Done." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment