3

Very long story short. In essence this is the problem.

I had some of my project files (new.cc) which I was working on for quite sometime. I created one backup of these files two months ago (old.cc), and basically what I did was > cp old.cc new.cc. And I have lost all the changes made in last two months.

Is there any way to recover these files? Any help is appretiated.

Zanna
  • 70,465
  • 4
    You have learned a painful lesson. Backing up every 2 months for something that's actively changed is not adequate. – Organic Marble May 26 '19 at 01:50
  • 3
    all software developers do this error ... only once ... daily backups to multiple places ... use a remote source code repository like github.com ... make your edits on a dir which lives on dropbox so current computer can meltdown with no loss of precious files – Scott Stensland May 26 '19 at 01:50
  • 2
    If you wish to recover a deleted file immediately stop using that computer NOW ... over time deleted files will become unrecoverable however if you perform forensics immediately after file got deleted your chances of success increase – Scott Stensland May 26 '19 at 02:02

1 Answers1

3

In short, unfortunately, there is no way to recover the newer versions of your files, unless you still have a copy elsewhere. Your copy command has overwritten your new versions with the old versions.

The copy command copies files from the source (old.cc in your example) to the destination (new.cc in your example). If files with the same name exist in the destination (in your case the newer versions), they will be overwritten. By default, the command cp will not ask if you want the file to be overwritten unless you supply the -i (--interactive) option, as in `cp -i .

The mistake was that you swapped source and destination. You really wanted to execute cp new.cc old.cc ("copy new to old") rather than cp old.cc new.cc.

Data recovery - As outlined here, there are ways to recover deleted information. As a matter of fact, the copy operation does not physically overwrite your information on the disk because of the way cp works on an ext formatted file system. That means that the bits and bytes of your new versions may still be somewhere on your hard disk. However, if you attempt do it yourself, it will be a huge challenge to recover these bytes to files that will have a random name, then manually inspect all of your possibly thousand reconstructed files to determine for each file if the file is still usable and what it represents. If you give it to a specialized data recovery service, it will cost a lot.

vanadium
  • 88,010