Skip to content

Instantly share code, notes, and snippets.

@saetia
Last active June 26, 2017 16:59

Revisions

  1. saetia revised this gist Jun 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    ruby -e "$(curl -fsSkL raw.github.com/gist/2369908/cd90a23b10d224284efe8dfdd5ccd3d3d328600c/parse.rb)" /Users/Joel/site.db.121010.dump
    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
  2. saetia revised this gist Oct 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    ruby -e "$(curl -fsSkL raw.github.com/gist/2369908/6fe8fdc1c20f97c431cb9326c6ccc78effb9bd7b/parse.rb)" /Users/Joel/site.db.121010.dump
    ruby -e "$(curl -fsSkL raw.github.com/gist/2369908/cd90a23b10d224284efe8dfdd5ccd3d3d328600c/parse.rb)" /Users/Joel/site.db.121010.dump

    ruby parse.rb site.120411.dump
  3. saetia revised this gist Oct 10, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions parse.rb
    Original file line number Diff line number Diff line change
    @@ -13,11 +13,11 @@
    d = File.new(dumpfile, "r")
    outfile = false
    table = ""
    directory = File.basename(dumpfile).gsub(/[^0-9a-z]/i, '')+'.tables'
    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, '')
    table = $1.gsub(/[^0-9a-z\.\_]/i, '')
    puts("\033[32mfound\033[0m #{table}\n")
    outfile = File.new("#{directory}/#{table}.sql", "w")
    end
  4. saetia revised this gist Oct 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    ruby -e "$(curl -fsSkL raw.github.com/gist/2369908/ee883b0eb427b43335ba31eb3fb9e59eaec7c2d2/parse.rb)" /Users/Joel/site.db.121010.dump
    ruby -e "$(curl -fsSkL raw.github.com/gist/2369908/6fe8fdc1c20f97c431cb9326c6ccc78effb9bd7b/parse.rb)" /Users/Joel/site.db.121010.dump

    ruby parse.rb site.120411.dump
  5. saetia revised this gist Oct 10, 2012. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions parse.rb
    Original file line number Diff line number Diff line change
    @@ -17,9 +17,7 @@
    Dir.mkdir(directory) unless File.directory?(directory)
    while (line = d.gets)
    if line =~ /^-- Table structure for table .(.+)./
    table = $1
    table.gsub(/[^0-9a-z]/i, '')!

    table = $1.gsub(/[^0-9a-z]/i, '')
    puts("\033[32mfound\033[0m #{table}\n")
    outfile = File.new("#{directory}/#{table}.sql", "w")
    end
  6. saetia revised this gist Oct 10, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion parse.rb
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,8 @@
    Dir.mkdir(directory) unless File.directory?(directory)
    while (line = d.gets)
    if line =~ /^-- Table structure for table .(.+)./
    table = $1.gsub(/[^0-9a-z]/i, '')!
    table = $1
    table.gsub(/[^0-9a-z]/i, '')!

    puts("\033[32mfound\033[0m #{table}\n")
    outfile = File.new("#{directory}/#{table}.sql", "w")
  7. saetia revised this gist Oct 10, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion parse.rb
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,8 @@
    Dir.mkdir(directory) unless File.directory?(directory)
    while (line = d.gets)
    if line =~ /^-- Table structure for table .(.+)./
    table = $1.gsub(/[^0-9a-z]/i, '')
    table = $1.gsub(/[^0-9a-z]/i, '')!

    puts("\033[32mfound\033[0m #{table}\n")
    outfile = File.new("#{directory}/#{table}.sql", "w")
    end
  8. saetia revised this gist Oct 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parse.rb
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@
    Dir.mkdir(directory) unless File.directory?(directory)
    while (line = d.gets)
    if line =~ /^-- Table structure for table .(.+)./
    table = $1
    table = $1.gsub(/[^0-9a-z]/i, '')
    puts("\033[32mfound\033[0m #{table}\n")
    outfile = File.new("#{directory}/#{table}.sql", "w")
    end
  9. saetia revised this gist Oct 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parse.rb
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    d = File.new(dumpfile, "r")
    outfile = false
    table = ""
    directory = File.basename(dumpfile).gsub(/[^0-9a-z ]/i, '')+'.tables'
    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 .(.+)./
  10. saetia revised this gist Oct 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parse.rb
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    d = File.new(dumpfile, "r")
    outfile = false
    table = ""
    directory = File.basename(dumpfile)+'.tables'
    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 .(.+)./
  11. saetia revised this gist Oct 10, 2012. 2 changed files with 3 additions and 33 deletions.
    32 changes: 0 additions & 32 deletions extract_tables.pl
    Original file line number Diff line number Diff line change
    @@ -1,32 +0,0 @@
    #!/usr/bin/perl -w
    use strict;

    my $dump_file = shift @ARGV;
    my $out_dump_file = 'stripped_dump.sql';

    open DUMP, "<$dump_file" or die $!;
    open OUT, ">$out_dump_file" or die $!;

    my @required_tables = @ARGV;

    my $table_dump_started = 0;
    while (<DUMP>){

    if (index($_, 'CREATE TABLE') >= 0){

    $table_dump_started = 0;
    foreach my $table (@required_tables){

    if (index($_, "`$table`") >= 0){
    $table_dump_started = 1;
    last;

    }
    }
    }
    print OUT
    if $table_dump_started;
    }

    close OUT;
    close DUMP;
    4 changes: 3 additions & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1 +1,3 @@
    ruby parse.rb metropoliscoffee.db.120411.dump
    ruby -e "$(curl -fsSkL raw.github.com/gist/2369908/ee883b0eb427b43335ba31eb3fb9e59eaec7c2d2/parse.rb)" /Users/Joel/site.db.121010.dump

    ruby parse.rb site.120411.dump
  12. saetia revised this gist Apr 12, 2012. 1 changed file with 32 additions and 0 deletions.
    32 changes: 32 additions & 0 deletions extract_tables.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/usr/bin/perl -w
    use strict;

    my $dump_file = shift @ARGV;
    my $out_dump_file = 'stripped_dump.sql';

    open DUMP, "<$dump_file" or die $!;
    open OUT, ">$out_dump_file" or die $!;

    my @required_tables = @ARGV;

    my $table_dump_started = 0;
    while (<DUMP>){

    if (index($_, 'CREATE TABLE') >= 0){

    $table_dump_started = 0;
    foreach my $table (@required_tables){

    if (index($_, "`$table`") >= 0){
    $table_dump_started = 1;
    last;

    }
    }
    }
    print OUT
    if $table_dump_started;
    }

    close OUT;
    close DUMP;
  13. saetia revised this gist Apr 12, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion parse.rb
    Original file line number Diff line number Diff line change
    @@ -13,11 +13,13 @@
    d = File.new(dumpfile, "r")
    outfile = false
    table = ""
    directory = File.basename(dumpfile)+'.tables'
    Dir.mkdir(directory) unless File.directory?(directory)
    while (line = d.gets)
    if line =~ /^-- Table structure for table .(.+)./
    table = $1
    puts("\033[32mfound\033[0m #{table}\n")
    outfile = File.new("#{table}.sql", "w")
    outfile = File.new("#{directory}/#{table}.sql", "w")
    end
    if table != "" && outfile
    outfile.syswrite line
  14. saetia created this gist Apr 12, 2012.
    1 change: 1 addition & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ruby parse.rb metropoliscoffee.db.120411.dump
    26 changes: 26 additions & 0 deletions parse.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/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 = ""
    while (line = d.gets)
    if line =~ /^-- Table structure for table .(.+)./
    table = $1
    puts("\033[32mfound\033[0m #{table}\n")
    outfile = File.new("#{table}.sql", "w")
    end
    if table != "" && outfile
    outfile.syswrite line
    end
    end
    end