9

I have a file that's downloading (from a source that's hard to re-download from), but accidentally deleted from the filesystem namespace (/tmp/blah), and I'd like to recover this file.

Normally I could just cp /proc/$PID/fd/$FD /tmp/blah, but in this case that would only get me a partial snapshot, since the file is still downloading. Furthermore, once the download completes, the downloading process (e.g. Chrome) will close the FD.

Any way to recover by inode/create a hard link? Any other solutions? If it makes any difference, I'm mainly concerned with ext4.

4 Answers 4

12

Try using tail to copy the file continually:

tail -c +0 -f /proc/$pid/fd/$fd > filename

Of course, you will have to stop the tail process by hand (or some other external means) when the download has finished.

1
  • Works like a charm. I guess this was much easier than I thought, since all you need is really just another program that opens the same file to keep it around.
    – xyzzyrz
    Mar 15, 2011 at 18:51
4

The fdlink project, consisting of a Linux kernel module and simple application, purports to create a new link to an open file descriptor. I haven't tried it.

0
1

This will get the job done, though not through by recovering the inode:

cp /proc/$PID/fd/$FD /tmp/blah
kill $PID
wget -c $URL -O /tmp/blah

Or just manually stop the download in Chrome if you don't want to kill the whole browser.

3
  • If only the problem were so simple that I could just resume-/re-download! I clarified the question to indicate that I can't assume I can re-download.
    – xyzzyrz
    Feb 16, 2011 at 21:27
  • Sounds like trouble :-) It seems like any inode-based hacks are way too low-level and filesystem-specific.
    – Pavel
    Feb 17, 2011 at 14:51
  • Yeah, I just also added this to my question: if it makes any difference, I'm mainly concerned with ext4.
    – xyzzyrz
    Feb 18, 2011 at 4:12
0

If you want to do a hard link on this, you have to use the -s option (see man ln) so in the fd directory run ls -f and find out the filenumber (mostly two-digit numbers) and make a ln NUMBER destination-file -s

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .