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.
total 337407844
drwx------ 2 tv tv 4096 Dec 17 22:47 .
drwxrwxrwx 15 tv tv 4096 Dec 17 22:44 ..
-rw-r--r-- 1 root root 423343556 Dec 14 07:10 I303109.RCN
-rw-r--r-- 1 root root 2990538924 Dec 13 19:05 I303107.RCN
-rw-r--r-- 1 root root 1023691768 Dec 13 08:10 I319494.RCN
-rw-r--r-- 1 root root 1023622348 Dec 13 07:45 I327684.RCN
-rw-r--r-- 1 root root 423735892 Dec 13 07:10 I327682.RCN
-rw-r--r-- 1 root root 466749476 Dec 12 15:43 I135169.RCN
-rw-r--r-- 1 root root 1023314212 Dec 12 07:45 I098309.RCN
-rw-r--r-- 1 root root 1022459928 Dec 12 06:35 I098306.RCN
-rw-r--r-- 1 root root 2458822948 Dec 9 22:50 I139264.RCN
-rw-r--r-- 1 root root 2129683736 Dec 9 21:30 I323592.RCN
-rw-r--r-- 1 root root 466735992 Dec 9 15:43 I323590.RCN
-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.
mysql> select basename,lastmodified,filesize from recorded limit 10;
+---------------------------+---------------------+------------+
| basename | lastmodified | filesize |
+---------------------------+---------------------+------------+
| 1003_20081003230000.mpg | 2008-10-07 21:53:49 | 6197765380 |
| 1093_20080320232600.mpg | 2008-03-20 23:25:31 | 0 |
| 1075_20060301191300.mpg | 2006-03-24 22:48:42 | 0 |
| 1002_20080729160500.mpg | 2008-07-29 19:20:30 | 3679223940 |
| 592251_20081217072000.mpg | 2008-12-17 07:20:02 | 0 |
| 1002_20080911143500.mpg | 2008-09-11 16:41:44 | 3486101572 |
| 1002_20080923143500.mpg | 2008-09-23 16:49:41 | 3679789684 |
| 1033_20081110153500.mpg | 2008-11-10 15:47:12 | 338877000 |
| 1002_20080922144000.mpg | 2008-09-22 16:47:38 | 3485505140 |
| 1002_20080721160500.mpg | 2008-07-23 20:52:16 | 3679559444 |
+---------------------------+---------------------+------------+
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
CREATE TABLE `temp2` (
`size` bigint(20) default NULL,
`oldname` varchar(255) default NULL,
`lastmod` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=latin1
And parsed the content of my lost+found directory into a set of insert statements
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
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 ..