WP Offload Media from Delicious Brains is a fantastic product. It allows you to offload WordPress’ media library to Amazon S3, DigitalOcean Spaces, or Google Cloud Storage. Recently I removed WP Offload Media from a legacy WordPress multisite. This is a recap of the steps I took.
Extra complexity for an already complex site.
The site I’m working with is a legacy multisite. That means files are uploaded in the following location: /wp-contents/blogs.dir/<subsite ID>/files/
. I had offloaded about 40GBs to Amazon S3 and configured WP Offload Media to remove the local copy in order to save local disk space. However considering there are hundreds of subsites with many possible other plugins in use, there really should be a local copy of the media files. Hence I decided to just revert back to WordPress defaults and remove WP Offload Media.
WP Offload Media has smart safe guards built-in.
If you deactivate WP Offload Media all media URLs safely revert back from Amazon S3 urls to local URLs. That means as long as you have a local copy of the media files than you can safely remove WP Offload Media by simply removing the plugin.
There are built in methods for moving media back to a local copy, however it’s also fine to manually move the files back yourself. Due to the large amount of data I decided to use rclone
, a command line sync utility, rather than use the built-in sync method.
Syncing files with Rclone
This turns out to be a two part process as the default directory paths in WP Offload Media aren’t compatible with the multisite legacy style.
First copy down everything from S3 bucket to your local computer using rclone. The rclone sync
command will override anything in the destination so be sure this is either a new directory or an empty folder.
rclone sync amazon-s3:bucket_name/ ~/Desktop/bucket_name/ --progress
WP Offload Media stores uploaded content in the format of /sites/<subsite ID>/
which doesn’t match the legacy format of blogs.dir/<subsite ID>/files/
. In order to mimic the old format the following bash script will loop through each subsite and create a /files/
folder and then move all content within that new folder.
cd ~/Desktop/bucket_name/uploads/sites/
for site in */
do
echo "Processing $site"
cd $site
mkdir files/
for d in */
do
echo "moving $d to files/"
mv $d files/
done
cd ..
done
Now that the local copy of the files match the live legacy multisite, the last part is to copy up only missing files to live website. That can be accomplished using rclone copy
with argument --ignore-existing
to skip over any files which already exist.
local_folder=~/Desktop/bucket-production/uploads/sites/
remote_folder=public/wp-content/blogs.dir/
rclone copy $local_folder sftp-sitename:${remote_folder} --ignore-existing --progress
Other housecleaning recommendations
With the media library back to WordPress’ default, WP Offload Media can be removed. If there are no plans to reuse then you can take the extra steps and manually walk through these steps: https://deliciousbrains.com/wp-offload-media/doc/uninstall/.
One benefit begin free of WP Offload Media is that the media files can now be managed locally via SSH. I recommend checking for any orphaned upload directories. On my site I was able to locate and remove 60 orphaned directories saving over 2GBs of storage. Also it’s a good idea to re-run WP Smush Pro which will optimize any previous media files which may have been missed.