Offload Media Manual Upload
Prerequisites:
- Rclone installed and configured.
- Git Bash (or PowerShell) for running commands.
- R2 bucket set up (e.g., with Cloudflare or another compatible provider).
- Ensure your WP Offload Media Lite is already set up and configured to use your R2 endpoint.
Step 1: Configure Rclone for R2
-
Install Rclone (if not already installed):
Download from the Rclone website and follow installation instructions for your platform (Windows, Linux, macOS). -
Configure Rclone for R2:
Open Git Bash or PowerShell and run:terminalrclone config
Follow the interactive prompts to create a new remote for your R2 bucket.
- Choose
n
for a new remote. - Name it (e.g.,
r2
). - Select
s3
as the storage type. - For provider, choose
Cloudflare R2
. - Enter your R2 Access Key ID and Secret Access Key.
- Set the endpoint (e.g.,
https://xxxxxx.r2.cloudflarestorage.com
). - Accept the defaults for other options unless you have specific requirements.
Note: You can edit the config file later at
~/.config/rclone/rclone.conf
if needed. - Choose
-
Verify Rclone Remote:
List your bucket contents to verify the connection:terminalrclone ls r2:<bucket-name>
Step 2: Sync Files to R2 Bucket
-
Sync Media Files:
To sync only the media files (typically stored inwp-content/uploads
), run:terminalrclone sync /path/to/your/wp-content/uploads <config-profile>:<bucket-name>/<project_slug> --include "/20*/**"
- Replace
/path/to/your/wp-content/uploads
with the path to your local WordPressuploads
folder. - Replace
<bucket-name>
with your R2 bucket name (e.g.,cdn.agentimagehosting.com
). - Replace
<config-profile>
with your SSH profile configuration. - Replace
<project_slug>
with your project slug. - The
--include "/20*/**"
flag ensures only year-based folders (e.g.,2021
,2022
) are uploaded.
- Replace
-
Verify the Files Have Uploaded:
List the files in your bucket:terminalrclone ls r2:<bucket-name>/<project_slug>
This will show the files that have been successfully uploaded.
-
Add entries to
wp_as3cf_items
tableWithin your project directory, make a temporary file and copy snippet below (
offload.sql
). Do not commit this file- Replace
<region>
with s3 bucket region. - Replace
<bucket>
with s3 bucket name. - Replace all
<project_slug>
with your project slug.
Import using wp cli:
terminalwp db import offload.sql
Check
wp_as3cf_items
table entries to have the correct paths.offload.sqlINSERT IGNORE INTO wp_as3cf_items ( provider, region, bucket, path, original_path, is_private, source_type, source_id, source_path, original_source_path, extra_info, originator, is_verified ) SELECT 'aws', '<region>', '<bucket>', concat('<project_slug>/', pm.meta_value) AS path, concat('<project_slug>/', pm.meta_value) AS original_path, 0, 'media-library', p.id AS source_id, pm.meta_value AS source_path, pm.meta_value AS original_source_path, 'a:2:{s:13:"private_sizes";a:0:{}s:14:"private_prefix";s:0:"";}', 0, 1 FROM `wp_posts` p LEFT JOIN `wp_postmeta` pm ON pm.post_id = p.id AND pm.meta_key = '_wp_attached_file' WHERE p.post_type = 'attachment';
- Replace