<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: backup code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 18:16:00 GMT</pubDate>
    <description>DZone Snippets: backup code</description>
    <item>
      <title>Restore a single table from a large MySQL backup</title>
      <link>http://snippets.dzone.com/posts/show/4819</link>
      <description>Say, for some reason, you need to restore the entire contents of a single table from a HUGE mysqldump generated backup containing several tables. For example:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;create table `baz`;&lt;br /&gt;&lt;br /&gt;GIGS OF SQL YOU DON'T WANT;&lt;br /&gt;&lt;br /&gt;create table `foo`;&lt;br /&gt;&lt;br /&gt;A COUPLE THOUSAND LINES YOU DO WANT;&lt;br /&gt;&lt;br /&gt;create table `bar`;&lt;br /&gt;&lt;br /&gt;MORE SQL YOU DON'T WANT;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;With a little dash 'o ruby, you can extract just the part you want:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$ ruby -ne '@found=true if $_ =~ /^CREATE TABLE `foo`/i; next unless @found; exit if $_ =~ /^CREATE TABLE (?!`foo`)/i; puts $_;' giant_sql_dump.sql &gt; foo.sql&lt;br /&gt;$ cat foo.sql&lt;br /&gt;create table `foo`;&lt;br /&gt;&lt;br /&gt;A COUPLE THOUSAND LINES YOU DO WANT;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You can then easily restore that entire table:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$ mysql mydatabase -e 'drop table foo'&lt;br /&gt;$ mysql mydatabase &lt; foo.sql&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 28 Nov 2007 14:10:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4819</guid>
      <author>jnewland (Jesse Newland)</author>
    </item>
  </channel>
</rss>
