Last active
July 30, 2019 21:01
-
-
Save Daniel-Worrall/422a8ad2cf2ec966d0b43fd1dd2427f2 to your computer and use it in GitHub Desktop.
Backup all named local volumes on docker
This file contains 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
folder_name = "" # Dir.pwd | |
volumes = %x`docker volume ls` | |
arr = [] | |
volumes.scan(/local\s*(\w*)/) { |x| arr << x[0] } | |
arr.reject!{ |x| x =~ /^[0123456789abcdef]+$/ } | |
arr.each do |volume_name| | |
p %x`docker run --rm -v #{volume_name}:/volume_data -v #{folder_name}:/backup ubuntu tar cvf /backup/#{volume_name}.tar /volume_data` | |
end |
This file contains 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
folder_name = "" # Dir.pwd | |
Dir.chdir(folder_name) | |
Dir.glob("*.tar").each do |filename| | |
volume_name = filename[0..-5] | |
%x`docker run --rm -v #{volume_name}:/volume_data -v #{folder_name}:/backup ubuntu bash -c "cd /volume_data && tar xvf /backup/#{filename} --strip 1"` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment