scripting

Dec 19 2008

MythTV recover Lost+Found

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.

  1. total 337407844
  2. drwx------ 2 tv tv 4096 Dec 17 22:47 .
  3. drwxrwxrwx 15 tv tv 4096 Dec 17 22:44 ..
  4. -rw-r--r-- 1 root root 423343556 Dec 14 07:10 I303109.RCN
  5. -rw-r--r-- 1 root root 2990538924 Dec 13 19:05 I303107.RCN
  6. -rw-r--r-- 1 root root 1023691768 Dec 13 08:10 I319494.RCN
  7. -rw-r--r-- 1 root root 1023622348 Dec 13 07:45 I327684.RCN
  8. -rw-r--r-- 1 root root 423735892 Dec 13 07:10 I327682.RCN
  9. -rw-r--r-- 1 root root 466749476 Dec 12 15:43 I135169.RCN
  10. -rw-r--r-- 1 root root 1023314212 Dec 12 07:45 I098309.RCN
  11. -rw-r--r-- 1 root root 1022459928 Dec 12 06:35 I098306.RCN
  12. -rw-r--r-- 1 root root 2458822948 Dec 9 22:50 I139264.RCN
  13. -rw-r--r-- 1 root root 2129683736 Dec 9 21:30 I323592.RCN
  14. -rw-r--r-- 1 root root 466735992 Dec 9 15:43 I323590.RCN
  15. -rw-r--r-- 1 root root 1022747296 Dec 9 07:45 I323588.RCN

Obviously I wanted to recover my data.
So I had files with a wrong filename on a filesystem but with a correct timestamp and probably the right filesize.
Luckily the mythconverg.recorded table also gives me lots of information about the files that mythtv had originally stored the content in.

  1. mysql> select basename,lastmodified,filesize from recorded limit 10;
  2. +---------------------------+---------------------+------------+
  3. | basename | lastmodified | filesize |
  4. +---------------------------+---------------------+------------+
  5. | 1003_20081003230000.mpg | 2008-10-07 21:53:49 | 6197765380 |
  6. | 1093_20080320232600.mpg | 2008-03-20 23:25:31 | 0 |
  7. | 1075_20060301191300.mpg | 2006-03-24 22:48:42 | 0 |
  8. | 1002_20080729160500.mpg | 2008-07-29 19:20:30 | 3679223940 |
  9. | 592251_20081217072000.mpg | 2008-12-17 07:20:02 | 0 |
  10. | 1002_20080911143500.mpg | 2008-09-11 16:41:44 | 3486101572 |
  11. | 1002_20080923143500.mpg | 2008-09-23 16:49:41 | 3679789684 |
  12. | 1033_20081110153500.mpg | 2008-11-10 15:47:12 | 338877000 |
  13. | 1002_20080922144000.mpg | 2008-09-22 16:47:38 | 3485505140 |
  14. | 1002_20080721160500.mpg | 2008-07-23 20:52:16 | 3679559444 |
  15. +---------------------------+---------------------+------------+
  16. 10 rows in set (0.00 sec)

My first idea was to use the mysql filesystem engine to query the filesytem and write me a simple query however I totally failed to build that engine :(
(Anyone else successfull here ? )

So I created a temp table

  1. CREATE TABLE `temp2` (
  2. `size` bigint(20) default NULL,
  3. `oldname` varchar(255) default NULL,
  4. `lastmod` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
  5. ) ENGINE=MyISAM DEFAULT CHARSET=latin1

And parsed the content of my lost+found directory into a set of insert statements

  1. ls -l --time-style=long-iso | awk -F' ' '{print "insert into temp2 values (" $5 ",\"" $8"\",\""$6" "$7"\");"}'

From there is a matter of grabbing the matching filenames

  1. echo "select \"mv \" , oldname, basename from recorded, temp2 where temp2.size= recorded.filesize ;" | mysql mythconverg

And moving the actual files ... now all is back to normal ..