Skip to content

Instantly share code, notes, and snippets.

@mattsawyer77
Created March 23, 2012 02:36
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 mattsawyer77/2166314 to your computer and use it in GitHub Desktop.
Save mattsawyer77/2166314 to your computer and use it in GitHub Desktop.
shell script to extract XML data from a MySQL Workbench file
#!/usr/bin/env ruby
begin
def usage(message = nil)
if !message.nil?
print message + "\n"
end
print "\nusage: extract_workbench_data <MWB file> <XML file>\n\n"
end
if ARGV.length == 2
mwb_file, xml_file = ARGV
mwb_filetype = `file "#{mwb_file}"`
if !mwb_filetype.match(/zip/i)
raise "#{mwb_file} is not a MySQL Workbench file!"
end
xml_filetype = `file "#{xml_file}"`
if !xml_filetype.match(/xml/i)
raise "#{xml_file} is not a valid XML file!"
end
print "extracting XML from #{mwb_file}...\n"
`mkdir -p /tmp/workbench`
if $?.to_i != 0 then raise "could not create temporary directory!" end
`unzip "#{mwb_file}" -d /tmp/workbench`
if $?.to_i != 0 then raise "could not unzip #{mwb_file}!" end
print "overwriting #{xml_file} with Workbench data...\n"
`cp /tmp/workbench/document.mwb.xml "#{xml_file}"`
print "#{xml_file} extracted successfully.\n"
`rm -rf /tmp/workbench`
else
usage
end
rescue StandardError => err
print err.to_s + "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment