0

I recently just overwrote one of my sql dump file by doing the following command:

mysqldump -u root -pTucson85719@ Directory > directory.sql

is it possible to get back the file that is being overwritten?

3
  • Generally no. With some file systems like ZFS, recovery might be possible. Aug 25, 2014 at 1:19
  • WARNING: This has been crossposted to superuser.com/questions/802491/… VERY BAD...please do not do this.
    – mdpc
    Aug 25, 2014 at 3:23
  • The answer is already in your tags. Restore from backup. Otherwise pay somebody to reconstruct it by manually assembling each sector of the original file, if they didn't get overwritten already. Chances of success are slim.
    – kasperd
    Aug 25, 2014 at 23:01

1 Answer 1

2

First thing, you should enable noclobber so this does not happen again. The option will prevent overwriting an existing file with redirection (>). To enable it, add the option to your .bashrc:

$ echo 'set -o noclobber' >> ~/.bashrc

Now, recovering the fille won't be simple but it is possible that you may still find it in the drive data. If you know some of the text in the file, you could unmount the drive and grep for it:

$ sudo grep 'MySQL Data' /dev/sdb2 | strings > recovered.txt

Again, you aren't guranteed to find it but I have had some luck with this method in the past. Best of luck to you!

4
  • what do you mean by unmount the disk?
    – user79356
    Aug 25, 2014 at 3:09
  • 1
    Unmount is done by unmount /path/to/device. If the file is on the same partition as your OS installation, then you need to boot a live rescue CD and do the operation there. Aug 25, 2014 at 14:02
  • The problem with this method is that if the file is fragmented, one has to search for the different fragments separately. Aug 25, 2014 at 14:03
  • Yup. Not a fun process by any means but, as far as I know, your only shot. It has helped me in the past. But again, I emphasize noclobber and proper backups to prevent having to go through the stress of a hail mary. Aug 25, 2014 at 14:43

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