Skip to content

Instantly share code, notes, and snippets.

@DALDEI
Created March 19, 2017 23:26
Show Gist options
  • Save DALDEI/22f3d05c7a875699a443e056b61dd860 to your computer and use it in GitHub Desktop.
Save DALDEI/22f3d05c7a875699a443e056b61dd860 to your computer and use it in GitHub Desktop.
Backup/Restore Docker Volumes
# backup files from a docker volume into /tmp/backup.tar.gz
# from http://stackoverflow.com/questions/21597463/how-to-port-data-only-volumes-from-one-host-to-another
function docker-volume-backup-compressed() {
docker run --rm -v /tmp:/backup --volumes-from "$1" debian:jessie tar -czvf /backup/backup.tar.gz "${@:2}"
}
# restore files from /tmp/backup.tar.gz into a docker volume
function docker-volume-restore-compressed() {
docker run --rm -v /tmp:/backup --volumes-from "$1" debian:jessie tar -xzvf /backup/backup.tar.gz "${@:2}"
echo "Double checking files..."
docker run --rm -v /tmp:/backup --volumes-from "$1" debian:jessie ls -lh "${@:2}"
}
# backup files from a docker volume into /tmp/backup.tar
function docker-volume-backup() {
docker run --rm -v /tmp:/backup --volumes-from "$1" busybox tar -cvf /backup/backup.tar "${@:2}"
}
# restore files from /tmp/backup.tar into a docker volume
function docker-volume-restore() {
docker run --rm -v /tmp:/backup --volumes-from "$1" busybox tar -xvf /backup/backup.tar "${@:2}"
echo "Double checking files..."
docker run --rm -v /tmp:/backup --volumes-from "$1" busybox ls -lh "${@:2}"
}
@junedkhatri31
Copy link

Created a ready to use in server/local utility for the same - docker-volume-snapshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment