Last active
November 13, 2022 00:53
-
-
Save gpoole/37259529d21d9beff075b9d37a5cbca5 to your computer and use it in GitHub Desktop.
Tool to help backup the contents of Docker volumes to a tar file on the Docker host
This file contains hidden or 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 | |
# based on https://docs.docker.com/storage/volumes/#back-up-restore-or-migrate-data-volumes | |
container_name="$1" | |
volume_path="$2" | |
backup_path="$3" | |
function usage() { | |
echo "container-export.sh container_name container_path backup_path" | |
exit 1 | |
} | |
if [ -z "$backup_path" ]; then | |
usage | |
fi | |
backup_name="`basename "$backup_path"`" | |
backup_dir="`dirname "$backup_path"`" | |
mkdir -p "$backup_dir" | |
docker run --rm --volumes-from "$container_name" -v "$backup_dir:/backup" ubuntu tar cvf "/backup/$backup_name" "$volume_path" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment