XF 1.5 Recover Perm Deleted Thread and Posts From Backup

Brent W

Well-known member
Is there a query I can run against a backup of our database to restore one thread and the posts associated with it?q
 
If you permanently deleted it, it's gone forever :(. It's not easy to use data recovery tools on DBs either, sadly.

Have you got an older backup? If so, you could recover it to a temp DB and then extract that post/thread and reinsert it.

edit: ignore this post and check out the replies below, I misread the OP.
 
Last edited:
If you permanently deleted it, it's gone forever :(. It's not easy to use data recovery tools on DBs either, sadly.

Have you got an older backup? If so, you could recover it to a temp DB and then extract that post/thread and reinsert it.

Yes I have backups (first part of the sentence in my post).
 
Ah crap, sorry about that - I misread this :rolleyes:. No idea how I managed to miss the crucial word!

If you've got the thread ID, you can use an MySQL manager to select the thread and posts using:

SELECT * from xf_post WHERE thread_ID = XXX;
SELECT * from xf_thread WHERE thread_ID = XXX;

Most MySQL managers will then let you check all of the returned rows and save the data as an SQL query that you can re-run on your new database.

I'm using SQLyog (there's a free version) and it'll let you do just that, I've had to do it a couple of times before.
 
It looks like phpMyAdmin can do the same thing, using the export tool. Just export the results from the queries above:

Capture.webp

I've not tested the output results from phpMyAdmin, but just make sure it contains only INSERT queries and nothing about dropping, updating or deleting. You'll need to make sure it doesn't try to re-create the table or alter any other data.
 
Last edited:
I've just tested this quickly now, and you'll need to use the "export" button below the selected data, rather than above. Then, choose the following "custom" options:
  • Dump all rows
  • View output as text
  • Format-specific options > data
Then, you should end up with some SQL beginning like this:

INSERT INTO `xf_thread` (`thread_id`, `node_id`, `title........

Do the same for both tables, double check it looks ok, then run that on the current DB.
 
Back
Top Bottom