Last active
June 26, 2017 16:59
-
-
Save saetia/2369908 to your computer and use it in GitHub Desktop.
Parse MySQL dumps
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
ruby -e "$(curl -fsSkL https://gist.githubusercontent.com/saetia/2369908/raw/4bf9a6d36060582e69f02c314f66449971a7bb11/parse.rb)" /Users/Joel/site.db.121010.dump | |
ruby parse.rb site.120411.dump |
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
#!/usr/bin/ruby | |
if ARGV.length == 1 | |
dumpfile = ARGV.shift | |
else | |
puts("\033[31mhow to:\033[0m ruby parse.rb mysql.dump\n") | |
exit 1 | |
end | |
STDOUT.sync = true | |
if File.exist?(dumpfile) | |
d = File.new(dumpfile, "r") | |
outfile = false | |
table = "" | |
directory = File.basename(dumpfile).gsub(/[^0-9a-z\.\_]/i, '')+'.tables' | |
Dir.mkdir(directory) unless File.directory?(directory) | |
while (line = d.gets) | |
if line =~ /^-- Table structure for table .(.+)./ | |
table = $1.gsub(/[^0-9a-z\.\_]/i, '') | |
puts("\033[32mfound\033[0m #{table}\n") | |
outfile = File.new("#{directory}/#{table}.sql", "w") | |
end | |
if table != "" && outfile | |
outfile.syswrite line | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment