Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Backup and Restore MySQL Docker Volume
#!/usr/bin/env bash
# @see:
# @see:
# @see:
# The name of the volume to backup/restore:
# Backup the Docker Volume to an archive:
docker run --rm --volume $VOLUME:/var/lib/mysql -v $(pwd):/backup alpine:latest sh -c "tar cvf /backup/$VOLUME.tar /var/lib/mysql"
# Restore the archive back to a Docker Volume:
docker run --rm -v $VOLUME:/var/lib/mysql -v $(pwd):/backup alpine:latest sh -c "cd /var/lib/mysql && tar xvf /backup/$VOLUME.tar --strip 3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment