Skip to content

Instantly share code, notes, and snippets.

@CodyKochmann
Created July 11, 2021 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodyKochmann/360762db36860107d0d651d19b5e9ee5 to your computer and use it in GitHub Desktop.
Save CodyKochmann/360762db36860107d0d651d19b5e9ee5 to your computer and use it in GitHub Desktop.
How to backup docker volumes on a docker host.
#!/bin/bash
# this script backs up all existing docker volumes to archives
# by: Cody Kochmann
cd $(mktemp -d)
docker volume ls \
| grep -v 'volume-backups' \
| awk '/local/ {print "docker run -i --rm -v "$2":/outside:ro -v volume-backups:/bak --workdir /outside registry.gitlab.com/icody/containers/debian tar czfv /bak/"strftime("%Y.%m.%d.%H.%M.%S-",systime())$2".tar.gz ./"}' \
| tee backup-volumes.sh
bash -x backup-volumes.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment