XF 2.1 How to Restore Permanently Deleted Threads + Attachments from Backup?

tourmeister

Active member
Howdy,

So for the first time in 16 years, I just accidentally nuked every thread displaying on a page in a node because I somehow hit select all when I thought I had only selected the one thread I wanted to delete... I hit cancel when I realized it was taking longer to remove one thread than it should, so I am not exactly sure how many threads got deleted. I feel like puking... :sick:

The horrible thing about it is that these were Ride/Trip reports my members had posted and they included lots of images. I use AndyB's ConvertImage add-on to convert links to attachments. So I am assuming the attachments got nuked as well.

I DO have a very recent backup of the database because I just did the upgrade to XF 2.1 a few nights ago. I also have all the attachment files because I recently downloaded all of them for setting up a test XF install on my local machine with XAMPP.

Is there any way I can put all that back?

I am not an expert with MySQL or phpMyAdmin, so hopefully the steps are not too complicated if it is possible.

Could I create a new database from my backup, export the desired content, and then import that into my live database? Also, since I am not sure which threads got nuked, would it be worth truncating all threads for that node and restoring all threads to be sure I have them all without duplication? If so, how?

Also, if I just upload the attachment images from my local machine back to the attachment directory on the server, would that maintain the connections between the posts and the images?
 
Okay, so since I have a copy of my forum running on my local machine in XAMPP using that most recent backup, I can see exactly which threads got nuked and can get their IDs. So, is it possible to restore entire threads or does it have bee done by post?
 
It may just be best to restore a database backup. Not sure which route you want to go or if your asking how to restore a backup but if you have cPanel just go to backup wizard -> restore -> then restore the sql file from before. If the attachments are in the same place then you won't have lost anything except for what was after the backup was made. If you don't have cPanel you can do it in phpMyAdmin too by importing the database. Either way would work
 
The last back up that I did was Tuesday evening just before I upgraded my site to XF 2.1. I have not done a database backup since then, so not quite 48 hrs ago.

Since my database backup was done before the upgrade, would I need to resintall XF 2.012, restore the backup database, then upgrade the site to 2.1 again?
 
The last back up that I did was Tuesday evening just before I upgraded my site to XF 2.1. I have not done a database backup since then, so not quite 48 hrs ago.

Since my database backup was done before the upgrade, would I need to resintall XF 2.012, restore the backup database, then upgrade the site to 2.1 again?

You would need to make sure the files for 2.0.12 are present and correct in the same place they used to be and then restore the database from there. You don't need to reinstall 2.0.12 but you will need to upgrade the site to 2.1 again if the prior backup was for 2.0.12
 
Dang...

I was REALLY hoping there might be a way to export the threads in question from the copy of my site I have on my local machine and then import them back into the live site database so I wouldn't lose the last 48 hours of activity.

I've shut my site down to keep people from creating new content in the meantime.

What if I created a forum section on my localhost test site which has a copy of the deleted threads, then moved the threads in question to that new section. That way all the threads would have the same node ID. Then, I was thinking there would be a way to export all the necessary info keying off that forum ID. After that, I'd go to my live site, create a new forum section there with the same name, grab its node ID, and then import the threads into that new section on the live site. Finally, I'd move the threads from the temp forum section on the live site into the forum where they were located originally.

Is that even possible? Or am I just engaging in wishful thinking?

If so, what query would I run? I have no idea how to construct queries or what tables I'd need to be pulling info from?
 
I'm sure there's some kind of query you could run. We'll wait and see what someone else says as I don't use SQL queries often myself. Just answering your questions about the backup. Not saying it isn't possible
 
Looks like I will just have to wait until morning to see if the server company has a backup more recent than mine... If not, I'll just go back to the 2.012 version of the site, import the backup, and do the upgrade again. Sucks losing two days worth of new content, but the stuff that got nuked is worth it.

So tell me, how do you guys do automated daily backups? Even though I have been running a forum for 16 years, I am relatively new to the server side of things. I always had someone else handling that form me until about 6 months ago. I feel like I have been drinking from a fire hose on full blast trying to learn all the stuff since then.

I have WHM and cPanel access to my VPS.
 
Not sure if feasible:
  1. Restore from backup to a temp-site
  2. delete every thread in whole temp-site except the ones you want to keep
  3. use the XF-importers to import just these threads
You could try on a small scale on a newly setup XF without restoring the backup, but in theory that should work

HTH,
-Markus
 
I use WHM built in daily/weekly/monthly backups for server side. That's full site backups.

For the client side database backups I use a trick with Windows Live Mail. Which is not readily available anymore but is possible to download if you find it on the web. I have a script that emails the database backup every 6 hours to my administrator address on my cPanel and then gets sent to my Windows Live Mail client, basically directly to my computer. There's an option you can uncheck called "leave copy of messages on server" and the backup goes straight to your computer without having to even go to your server email.

I wrote a tutorial about it here if your interested in learning how it works:

 
I was REALLY hoping there might be a way to export the threads in question from the copy of my site I have on my local machine and then import them back into the live site database so I wouldn't lose the last 48 hours of activity.
There is, but it requries expert knowledge of XenForo data structures.

Basically you have to extract the necessary data from tables
  • xf_thread
  • xf_post
  • xf_thread_watch
  • f_thread_read
  • xf_thread_redirect
  • xf_thread_reply_ban
  • xf_thread_user_post
  • xf_thread_field_value
  • xf_attachment
  • f_attachment_data
  • xf_approval_queue
  • xf_poll
  • xf_poll_response
  • xf_poll_vote
  • xf_liked_content
  • xf_edit_hisotry
  • xf_draft
(I hope I did not forget one)
insert it into the approritate tables & fields in your production DB and copy the files back.

So tell me, how do you guys do automated daily backups? Even though I have been running a forum for 16 years, I am relatively new to the server side of things. I always had someone else handling that form me until about 6 months ago. I feel like I have been drinking from a fire hose on full blast trying to learn all the stuff since then.
We are running two database servers in an Master-Master replication setup in which only one is actively being used, eg. Active-Slave.
Additionally we have a dedicated backup slave running on ZFS that replicates from them.
We take daily snapshots from ZFS and send them to a dedicated backup server where we keep 7 days binary logs, 7 daily, 4 weekly and 12 monthly backups.
So in an emergency case we could perform a point in time recovery for the last 7 days.
 
Last edited:
I was thinking I can't be the first person to run into this problem. How can there not be an add-on that can extract that info from a backup copy of the database and import it into the live database? I understand though there might be issues with links to/from threads/posts if things like thread/post ids change from the backup version to the live version.

Regardless, I will just brute force the restoration from a backup and lose the content for the last 24-48 hours. It is maybe a few hundred general chatter messages. However, the threads that were deleted had hundreds of replies each, some over 300 replies because they were basically travel logs for long trips taken by some of my members containing thousands of photos.

I will be MUCH more careful about selecting threads... I still can't figure out how I accidentally selected all of them after very carefully checking just the one box for the thread I actually did intend to delete. Maybe an "Are you sure you want to select all" warning would be nice.

Thanks for the feed back on how to automate the backup process. I will DEFINITELY be getting on that pronto!
 
I sill have a VPS with HostGator that is good for several years because they don't do refunds after a certain time. It is essentially sitting there empty because I moved my live site over to KnownHost.

Is there a way I could automate the backup process and then have it automatically copy the files from my Knownhost VPs over to the HostGator VPS? I have a shared IP and a dedicated IP for the HG VPS, so could I go into WHM and create an account for that purpose without worrying about having some kind of domain name?
 
I was thinking I can't be the first person to run into this problem.
You are not.

The answer is the same though - you will need to restore from a backup.

There's a good reason why the hard delete function is a separate permission - it's not recommended to have it enabled for regular use.
 
There's a good reason why the hard delete function is a separate permission - it's not recommended to have it enabled for regular use.

And I normally don't have it enabled. I was in the process of removing old threads from the database. Like I said in my original post though, first time in 16 years... Fortunately, there is a backup that was made AFTER I did the upgrade to 2.1, so I don't lose much by restoring, just a day or so of basic chatter messages.
 
Sooo... it turns out that their last backup was right before I upgraded to 2.1...

They restored that backup. I verified that it was XF 2.012 as it was about 20 minutes before I did the upgrade.

So, I uploaded all the XF2.1 files, ran the command line upgrade: php cmd.php xf:upgrade, while in the /forums directory.

It started just fine, just like before, but then I got this...

195077

and then it drops me back to the command prompt.

During the upload process, the FTP disconnected once, I immediately logged back in and the upload picked up where it left off. Thinking that perhaps the manager.php file got corrupted by the disconnect, I did a search for the file name and found that there six different locations within the /src/XF directory structure where files with that name (but different sizes) exist. So I went to each location and uploaded that file to its corresponding location on my server. I then tried the upgrade again. No dice. I just keep getting the same error.

What do I do now?
 
Top Bottom