Everything is a Freaking DNS problem - scripting http://127.0.0.1:8080/blog/taxonomy/term/1132/0 en MythTV recover Lost+Found http://127.0.0.1:8080/blog/mythtv-recover-lostfound <p>My MythTV store lives on an LVM volume that is spread over 2 disks, one of them is an external USB disk. So the cleaninglady seems to have touched a cable and after coming back from holiday I had a read-only filesystem that afer a remount had about 350Gb in lost+found with irrelevant filenames.</p> <p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;"><ol><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">total 337407844</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">drwx------ 2 tv tv 4096 Dec 17 22:47 .</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">drwxrwxrwx 15 tv tv 4096 Dec 17 22:44 ..</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 423343556 Dec 14 07:10 I303109.RCN</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 2990538924 Dec 13 19:05 I303107.RCN</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 1023691768 Dec 13 08:10 I319494.RCN</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 1023622348 Dec 13 07:45 I327684.RCN</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 423735892 Dec 13 07:10 I327682.RCN</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 466749476 Dec 12 15:43 I135169.RCN</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 1023314212 Dec 12 07:45 I098309.RCN</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 1022459928 Dec 12 06:35 I098306.RCN</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 2458822948 Dec 9 22:50 I139264.RCN</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 2129683736 Dec 9 21:30 I323592.RCN</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 466735992 Dec 9 15:43 I323590.RCN</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">-rw-r--r-- 1 root root 1022747296 Dec 9 07:45 I323588.RCN</div></li></ol></pre></div></p> <p>Obviously I wanted to recover my data.<br /> So I had files with a wrong filename on a filesystem but with a correct timestamp and probably the right filesize.<br /> Luckily the mythconverg.recorded table also gives me lots of information about the files that mythtv had originally stored the content in.</p> <p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;"><ol><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">mysql&gt; select basename,lastmodified,filesize from recorded limit 10;</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">+---------------------------+---------------------+------------+</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">| basename | lastmodified | filesize |</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">+---------------------------+---------------------+------------+</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">| 1003_20081003230000.mpg | 2008-10-07 21:53:49 | 6197765380 |</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">| 1093_20080320232600.mpg | 2008-03-20 23:25:31 | 0 |</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">| 1075_20060301191300.mpg | 2006-03-24 22:48:42 | 0 |</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">| 1002_20080729160500.mpg | 2008-07-29 19:20:30 | 3679223940 |</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">| 592251_20081217072000.mpg | 2008-12-17 07:20:02 | 0 |</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">| 1002_20080911143500.mpg | 2008-09-11 16:41:44 | 3486101572 |</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">| 1002_20080923143500.mpg | 2008-09-23 16:49:41 | 3679789684 |</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">| 1033_20081110153500.mpg | 2008-11-10 15:47:12 | 338877000 |</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">| 1002_20080922144000.mpg | 2008-09-22 16:47:38 | 3485505140 |</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">| 1002_20080721160500.mpg | 2008-07-23 20:52:16 | 3679559444 |</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">+---------------------------+---------------------+------------+</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">10 rows in set (0.00 sec)</div></li></ol></pre></div></p> <p>My first idea was to use <a href="http://code.google.com/p/mysql-filesystem-engine/" rel="nofollow">the mysql filesystem engine</a> to query the filesytem and write me a simple query however I totally failed to build that engine :(<br /> (Anyone else successfull here ? )</p> <p>So I created a temp table</p> <p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;"><ol><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">CREATE TABLE `temp2` (</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> `size` bigint(20) default NULL,</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> `oldname` varchar(255) default NULL,</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> `lastmod` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">) ENGINE=MyISAM DEFAULT CHARSET=latin1</div></li></ol></pre></div></p> <p>And parsed the content of my lost+found directory into a set of insert statements<br /> <div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;"><ol><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">ls -l --time-style=long-iso | awk -F' ' '{print &quot;insert into temp2 values (&quot; $5 &quot;,\&quot;&quot; $8&quot;\&quot;,\&quot;&quot;$6&quot; &quot;$7&quot;\&quot;);&quot;}'</div></li></ol></pre></div></p> <p>From there is a matter of grabbing the matching filenames</p> <p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;"><ol><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">echo &quot;select \&quot;mv \&quot; , oldname, basename from recorded, temp2 where temp2.size= recorded.filesize ;&quot; | mysql mythconverg</div></li></ol></pre></div></p> <p>And moving the actual files ... now all is back to normal ..</p> http://127.0.0.1:8080/blog/mythtv-recover-lostfound#comments crash lost+found mysql mythtv opensource recovery scripting Fri, 19 Dec 2008 18:41:17 +0000 Kris Buytaert 843 at http://127.0.0.1:8080/blog