Here is what we have to do to fix PIXELS:

First, bring in the witch doctor/sorceress …


Create a new amazon AWS bucket. This will be the final location of the images.
Info on copying files bucket to bucket:

This will have to be done for both current buckets.*

Do not delete or remove the files from the two existing buckets until this entire process is completed!

Back up the database from Pixels. This is very important, and make sure the backup can be loaded back up into a wordpress install with no errors. This should probably be a local copy running on a docker or other virtual environment.

You will need to use a url replace plugin like velvetblues:

Another possible tool is better search & replace:

Before doing any operations here – you will need to have merged the files into the new bucket. It is crucial that the folder structure remain the same. WordPress uses year/month so it should be possible for these to merge with no conflicts or overwriting.

When you have the files in the new bucket, you will need to note the S3 url. 

I don’t have information on what s3 plugin is used on pixels, or what the urls that it creates in the database to point at the images on S3. 

At this point – configure the plugin to point to the new bucket, and upload a couple images. Verify that they are being uploaded and are being served from the correct bucket. 

Look in wp_posts and wp_posts_meta and note the url being used to link to the images on the new bucket. 

The url will be structured something like this:

https://[amazon bucket url]//[month]/[filename]

Once you have this worked out, you’ll need to do the find & replace, but ONLY for the url segments BEFORE the year/month/filename. That part of the URL must remain, otherwise you will not be able to link to the image. 
For example, if one of the existing urls is:

https://[old bucket url]//[month]/[filename]

You would only replace the part labeled “old bucket url” in the example above. 

The goal here is to replace all the broken urls with the correct urls pointing to the new s3 bucket. 
It is *VERY* important that all these steps are followed. You can’t do this on the live site because any errors run the risk of making the problem worse, and preventing any other recovery attempts. 

Once the local copy has been updated – make sure you have an untouched copy of the database from the live site, then try and load the database with the updated urls. 

It is very likely you will have to do this in stages due to size. I would recommend only updating the wp_posts and wp_post_meta tables to keep the size of the database export file manageable.

*We are dealing with about 20 gigabytes of images, probably one million total. Remember, there are four or five versions of every image ever submitted to Pixels, even if we only published a fifth of them.

That’s all we have to do! Hopefully we will have it done fairly quickly.