Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Missing Attachments After Upgrading to VB 4.2.3 Fix
BirdOPrey5's Avatar
BirdOPrey5
Join Date: Jun 2008
Posts: 10,610

The details of my life are quite inconsequential.

New York
Show Printable Version Email this Page Subscription
BirdOPrey5 BirdOPrey5 is offline 04-17-2016, 09:00 PM

NOTE: If you have downloaded vBulletin 4.2.3 files on or after July 5, 2016 you are not at risk of losing attachments as described below.

----

It has come to my attention that a bug fixed in VB 4.2.3 will in some cases cause the loss of some attachments on forums, particularly it seems older forums. The issue happens because the software deletes attachments it believes are no longer in use.

Anyone upgrading directly to 4.2.4 Beta 1 or above will not be affected.

Unfortunately many admins don't notice this right away, it might be weeks or months and by that time restoring to a pre-upgrade backup is not possible.

This fix requires a pre-upgrade backup of the database AND attachments (if saved in the file system) are available. Without the backup of both the database and attachments files there is no way to get back the deleted attachments.

There may well be better ways of doing this, I'm not claiming it is the best way, but I successfully used this to restore one site's attachments so I know it works.

Note: The database commands listed later assume no table prefix is in use. If you use a table prefix you will need to make appropriate changes to the code to account for the table prefixes.

Before starting make sure you take a fresh backup of your current database and files in case something goes wrong. This code is not officially supported, it is use at your own risk. There is no supported way to restore your old attachments.

From this point "old" refers to the old pre-4.2.3 backup. "New" refers to your live site.

1) Copy over the old attachment files over the new ones. Attachments shouldn't ever change so you'll overwrite a number of files but the deleted ones will return to their original locations. The new ones won't be affected. (If attachments are stored in the database skip this step.)

2) From your old backup export the following tables to individual .SQL files
  • attachment
  • attachmentcategoryuser
  • filedata

3) Edit each SQL file in a text editor. At the top of each file is a "CREATE TABLE" block of code, delete the entire block. Will look something like-

Code:
CREATE TABLE IF NOT EXISTS `attachment` (
  `attachmentid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `contenttypeid` int(10) unsigned NOT NULL DEFAULT '0',
  `contentid` int(10) unsigned NOT NULL DEFAULT '0',
  `userid` int(10) unsigned NOT NULL DEFAULT '0',
  `dateline` int(10) unsigned NOT NULL DEFAULT '0',
  `filedataid` int(10) unsigned NOT NULL DEFAULT '0',
  `state` enum('visible','moderation') NOT NULL DEFAULT 'visible',
  `counter` int(10) unsigned NOT NULL DEFAULT '0',
  `posthash` varchar(32) NOT NULL DEFAULT '',
  `filename` varchar(255) NOT NULL DEFAULT '',
  `caption` text,
  `reportthreadid` int(10) unsigned NOT NULL DEFAULT '0',
  `settings` mediumtext,
  `displayorder` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`attachmentid`),
  KEY `contenttypeid` (`contenttypeid`,`contentid`,`attachmentid`),
  KEY `contentid` (`contentid`),
  KEY `userid` (`userid`,`contenttypeid`),
  KEY `posthash` (`posthash`,`userid`),
  KEY `filedataid` (`filedataid`,`userid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=763 ;
But varies for each file.

Next Do a find / replace for the entire file.

Find: INSERT INTO
Replace With: INSERT IGNORE INTO

Then save the .SQL file. (Again you need to do this for all 3 files)

4) Now go to your live database and IMPORT each of the 3 files into your live database.

The "INSERT IGNORE INTO" commands will just discard any duplicate (existing) entries without error. All the deleted records will be restored.

5) RUN that MySQL command to fix the bug:

Code:
UPDATE filedata
LEFT JOIN (
   SELECT filedataid, COUNT(attachmentid) AS actual
   FROM attachment
   GROUP BY filedataid
) list USING (filedataid)
SET refcount = IFNULL(actual, 0)
WHERE refcount <> IFNULL(actual, 0)
6) Now go to the old database, go to the post table. Run the command:
Code:
SELECT attach, postid FROM post WHERE attach > 0
Export the results of this command as a CSV File.

7) Open the CSV file in a spreadsheet program like Microsoft Excel. In the speadsheet add a column before the attach list, add a column between attach and postid.

In the first column add the text:
Code:
UPDATE post SET attach =
And copy it to boxes in the column, as far down as there is data.

In the middle column (between attach and postid) add the text:
Code:
 WHERE postid =
Then copy this text to all rows like above.

Finally in a column to the right of the postid column add the text:
Code:
 AND attach = 0;
And again, copy this text to all columns.

When finished it will look something like this:
Attachment 154706

8) Export or Save the document again as a CSV file.

9) Open the new CSV file in a text editor. You're going to need to use find/replace to remove the commas and double quotes (if they exist) replace them all with spaces.

It's going to look something like this:
Attachment 154705

Save this now as a .SQL file.

10) Import the file to the live database. This should update any old posts that used to have attachments recorded that don't anymore. Nothing else will change in the post but the # of attachments. If the post has at least one attachment already it won't be touched.

That should do it.

One more step- to see the changes immediately the post cache must be cleared so EMPTY the postparsed table in the database. That will clear the the post cache so changes to cached posts are visible.

In the Admin CP -> Maintenance, run the Clear System Cache option as well.

Also in Maintenance, go to General Update Tools, and Rebuild Thread Information, followed by Rebuild Forum Information.
Reply With Quote
  #2  
Old 06-28-2016, 09:38 PM
SilverBoy SilverBoy is offline
 
Join Date: Feb 2002
Location: Libya
Posts: 497
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you BirdOPrey5

By luck I see your article, after that I checked my forum and found that there are about 40000 attachments deleted !!

Fortunately I get a copy of my DB before 7 days from the day I made the upgrade in it, and go throw your steps and get my attachments back.

Thank you.
Reply With Quote
Благодарность от:
BirdOPrey5
  #3  
Old 07-06-2016, 04:03 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I see that the VB 4.2.3 files have been updated to prevent this issue. As long as you download the 4.2.3 files from this point onwards you will not have to worry about this issue. :up:
Reply With Quote
  #4  
Old 09-08-2016, 05:53 PM
dwwright dwwright is offline
 
Join Date: Feb 2009
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for posting this. I did download the 4.2.3 just last week and still had this issue, so not sure that the fix is in the current upgrade files to prevent it.
Reply With Quote
Благодарность от:
BirdOPrey5
  #5  
Old 09-09-2016, 11:07 AM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm quite sure it is - in class_upgrade_423.php
Reply With Quote
  #6  
Old 09-09-2016, 04:57 PM
dfe dfe is offline
 
Join Date: Oct 2006
Posts: 56
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I did the 4.2.3 install, upgrading from 3.8.9 and lost all the attachments, I did details on the vbulletin.com forum the process I used to recover, but key to my recover was the fact that I had a backup I made directly after the upgrade.

The issue was not with the upgrade, but rather with one of the maintenance scripts that ran a few hours after the upgrade.

(Edit: I downloaded the upgrade, and did the upgrade 30 May....)
Reply With Quote
  #7  
Old 09-09-2016, 06:14 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Edit: I downloaded the upgrade, and did the upgrade 30 May....
Which is a few weeks before the fix was applied to the 423 upgrade code. (It was originally only in 424)
Reply With Quote
  #8  
Old 09-09-2016, 10:28 PM
dwwright dwwright is offline
 
Join Date: Feb 2009
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, doesn't matter, but the instructions above worked great, everything is restored and working...Thanks.
Reply With Quote
Благодарность от:
TheLastSuperman
  #9  
Old 02-28-2020, 05:14 PM
webspider webspider is offline
 
Join Date: Jun 2003
Location: Canada
Posts: 175
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have a similar but different issue. I have an old board v2/3 that has been updated continuously to 4.25. All my attachments are there but I can't move on to a newer board. as 3/4 of the attachments (265K import does about 40k) show as not there. I'm not sure this is what I'm looking for but might it fix my problem?
Reply With Quote
  #10  
Old 03-04-2020, 12:37 AM
Mattwhf Mattwhf is offline
 
Join Date: May 2016
Posts: 190
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I faced this issue in the past, I lost attachments and I must reupload some. Luckily, my forum has less attachments so the work is not more.

Thanks for your mod!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:04 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05902 seconds
  • Memory Usage 2,325KB
  • Queries Executed 26 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (6)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete