Advertisement
mindthump

Backup Docker Volume

Jul 12th, 2020
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.71 KB | None | 0 0
  1. # After a bit of research, it turned out it’s actually pretty easy to back up volumes using volume mounts and a tar utility. For example to backup some_volume to /tmp/some_archive.tar.bz2, you can simply run:
  2.  
  3. docker run --rm -v some_volume:/volume -v /tmp:/backup alpine tar -cjf /backup/some_archive.tar.bz2 -C /volume ./
  4.  
  5. # And to restore it, just run:
  6.  
  7. docker run --rm -v some_volume:/volume -v /tmp:/backup alpine sh -c "rm -rf /volume/* /volume/..?* /volume/.[!.]* ; tar -C /volume/ -xjf /backup/some_archive.tar.bz2"
  8.  
  9. # Note: As a safety precaution, I advise you to stop all the containers using the volume being backed-up or restored, otherwise an inconsistent / intermediate state might be archived or recovered.
  10.  
  11. # ... From "https://medium.com/@loomchild/backup-restore-docker-named-volumes-350397b8e362"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement