I made a big mistake!, I have a vps(centos7) server and for deleting temp files have a command:

 sudo find /tmp -type f -atime +10-delete

this command is good but this time by mistake i forgot to write tmp after / and you all know what happened next...!!

Gratefully i had a backup of all my files and almost restore everything. But the problem is that my MySQL backup is for almost 30 days ago and they're actually useless! All MySQL files in /var/lib/mysql folder are deleted and therefor in phpmyadmin all databases are empty (because of all files deleted and folders remains databases exists but empty)

another great thing that first off all i noticed is that my Sites were running without any problems! then i found this post and realize what actually happens: recover accidentally deleted MySQL files . I do the instruction bellow

mysqldump --opt <database> > database.sql

but this command give me same empty databases!! now what should i do to recover my databases from MySQL process that has the new ones? Is there any way?

Thank you very much for guidance...

  • 2
    Can you still see the actual database(s) and tables when you do a SHOW DATABASES or SHOW TABLES query? And is there still any data returned when you do a SELECT? – Oldskool Oct 23 '18 at 9:38
  • yes, databases are still exists because of that command only delete files not folders but all of files in databases are deleted and "SELECT" don't return any data. – pooya Oct 23 '18 at 10:16
  • 1
    You should stop the VPS immediately, take a snapshot of it, and then start looking into undelete options for the filesystem it uses. But if you actually did restore a bunch of files, you might have overwritten the important data you want to recover. – Michael Hampton Oct 23 '18 at 14:26
  • How can i snapshot of my vps? if i stop the vps MySQL process will release my database files! – pooya Oct 24 '18 at 13:34
  • Is there any way to execute command as MySQL process? mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql – pooya Oct 25 '18 at 10:56

You can always use testdisk suite which comes default on most recent distros and see if you can recover the files

  • Welcome to ServerFault. Answers should be able to stand alone, so this should include some procedure to follow the process. Link only answers are not allowed. – Cory Knutson Oct 23 '18 at 17:26
  • Actually this won't work. First of all, even if you manage to recover the files they will be corrupt and the database won't start. Second, the recovered files will miss chunks of data. A reason for that it testdisk tries to reconstruct a file and if some pieces of it are missing it fills gaps with zero. You however don't care about the files, you need records. – akuzminsky Oct 24 '18 at 4:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.