S3 Media Sync

Plugin WordPress mã nguồn mở — đồng bộ Media Library lên mọi S3-compatible storage. AWS S3, iDrive E2, MinIO, Cloudflare R2, DigitalOcean Spaces và hơn thế nữa.

v1.0.1 GPLv2+ PHP ≥7.4 · WP ≥5.8 CODE TOT

Hướng dẫn sử dụng

Plugin giúp đồng bộ media WordPress lên object storage — tiết kiệm dung lượng hosting, tối ưu băng thông, tích hợp CDN dễ dàng.

Cài đặt

Có 2 cách cài đặt plugin S3 Media Sync:

Cách 1: Clone từ GitHub (khuyến nghị)

# SSH vào server, vào thư mục plugins
cd wp-content/plugins/
git clone https://github.com/codetot-web/s3-media-sync.git
cd s3-media-sync
composer install --no-dev --optimize-autoloader

Cách 2: Download release ZIP

# Tải file ZIP từ GitHub Releases
wget https://github.com/codetot-web/s3-media-sync/releases/download/v1.0.1/s3-media-sync.zip
unzip s3-media-sync.zip -d wp-content/plugins/

Sau khi cài, vào WP Admin → Plugins → kích hoạt "S3 Media Sync".

Cấu hình cơ bản

  1. Vào Settings → S3 Media Sync
  2. Chọn Storage Provider: AWS S3 hoặc S3-Compatible
  3. Nhập Access Key, Secret Key, Bucket name
  4. Click Test Connection để kiểm tra
  5. Bật Enable Sync và chọn chế độ sync:
    • Instant: Upload ngay lập tức — phù hợp media nhỏ
    • Background: Hàng đợi WP-Cron 10 phút — phù hợp media lớn
  6. Save settings

Tính năng chính

🔄

Auto-sync

Tự động upload lên S3 khi thêm media vào WordPress. Hỗ trợ Instant + Background mode.

📐

All image sizes

Upload original + tất cả resized variants. Chỉ xoá local khi tất cả sizes upload thành công.

🔁

URL Rewriting

Serve media từ S3/CDN. Rewrite qua WordPress filters: srcset, content, Yoast SEO, Elementor.

🗑️

Delete sync

Xoá media trong WordPress → tự động xoá object trên S3. Gồm original + tất cả sizes.

📦

Bulk sync

Sync toàn bộ media library cũ qua Tools page. Resumable — dừng và tiếp tục bất kỳ lúc nào.

🧹

Dọn local

Sau khi sync thành công, xoá local files để giải phóng dung lượng hosting.

Providers được hỗ trợ

AWS S3 DigitalOcean Spaces Cloudflare R2 Wasabi Backblaze B2 MinIO (self-hosted) iDrive E2 Any S3-compatible endpoint

Câu hỏi thường gặp

Plugin có xoá file gốc không?

Mặc định không. Bạn phải bật Delete local after upload trong Settings để xoá local sau khi sync.

Làm sao để serve media qua CDN?

Nhập CDN URL (vd: https://cdn.example.com) vào Public Bucket URL. Plugin tự động append bucket + file path.

Có support multisite không?

Có. Mỗi site trong network có thể dùng chung bucket hoặc riêng.

Hướng dẫn DevOps

Cấu hình server, deployment, automation và CLI dành cho team vận hành.

Requirements

  • WordPress ≥ 5.8
  • PHP ≥ 7.4
  • Composer (để cài AWS SDK)
  • WP-CLI (optional, khuyến nghị)

Deployment pipeline

Add vào deployment script của dự án:

#!/bin/bash
# deploy-s3-media-sync.sh
SITE_PATH=/var/www/example.com

# Clone/update plugin
if [ -d "$SITE_PATH/wp-content/plugins/s3-media-sync" ]; then
  cd "$SITE_PATH/wp-content/plugins/s3-media-sync"
  git pull origin master
else
  git clone https://github.com/codetot-web/s3-media-sync.git "$SITE_PATH/wp-content/plugins/s3-media-sync"
  cd "$SITE_PATH/wp-content/plugins/s3-media-sync"
fi

composer install --no-dev --optimize-autoloader

# Activate plugin (nếu chưa active)
wp plugin activate s3-media-sync --path="$SITE_PATH"

# Sync existing media
wp s3 sync --batch=50 --path="$SITE_PATH"

Cấu hình S3-Compatible providers

ProviderEndpointRegionNotes
AWS S3leave blankap-southeast-1Virtual-hosted URLs
Cloudflare R2https://<accountid>.r2.cloudflarestorage.comautoPath-style, zero egress
iDrive E2https://<B>.e2.idy.idrivee2.comus-east-1Check iDrive docs
MinIOhttps://minio.example.comus-east-1Self-hosted
DigitalOcean Spaceshttps://<region>.digitaloceanspaces.comsgp1Path-style
Wasabihttps://s3.<region>.wasabisys.comap-northeast-1No egress fees

Automation với CLI

Plugin CLI commands có thể dùng trong cron, CI/CD và deployment scripts:

# Cron: daily sync check lúc 3h sáng
0 3 * * * /usr/local/bin/wp s3 sync --batch=50 --path=/var/www/example.com

# Post-deployment: verify connection
wp s3 status

# Reset và re-sync sau migration
wp s3 reset
wp s3 sync

# Xoá local files sau khi xác nhận S3 OK
wp s3 delete-local

Troubleshooting

Connection failed

Kiểm tra: credentials, bucket tồn tại, endpoint đúng, firewall không block outgoing.

Files không sync

Kiểm tra: "Enable Sync" được bật, AWS SDK installed, file tồn tại trên disk, WP-Cron hoạt động (nếu dùng Background mode).

URL không rewrite

Kiểm tra Public Bucket URL đã cấu hình đúng. Verify URL trỏ đến bucket và bucket public readable.

Marketing Toolkit

Tính năng, USP, messaging và tài liệu cho team Marketing.

Giới thiệu ngắn

S3 Media Sync là plugin WordPress mã nguồn mở (GPLv2) giúp đồng bộ toàn bộ thư viện media lên S3-compatible storage — AWS S3, iDrive E2, MinIO, Cloudflare R2, DigitalOcean Spaces. Plugin tự động upload khi thêm media, hỗ trợ bulk sync thủ công, URL rewriting qua CDN, và dọn file local sau sync.

USP (Unique Selling Points)

🆓

100% Mã nguồn mở

GPLv2. Không premium, không upsell, không tính năng khoá. Tất cả tính năng đều miễn phí.

🔌

Mọi S3-compatible provider

AWS S3, R2, iDrive E2, MinIO, DO Spaces, Wasabi, Backblaze B2 — không lock-in.

🛠️

CLI-first design

Đầy đủ WP-CLI commands. Plugin được xây cho automation, không chỉ admin UI.

📦

Bundled AWS SDK

AWS SDK for PHP bundled, vendor optimized chỉ ~4.4MB. Không cần cài thêm dependencies.

🕐

Background sync

Sync qua WP-Cron cho large library. Không timeout browser, không block user.

🔐

Security-first

PCP compliant, credentials sanitized, SSL verify, wp_delete_file(), prepared SQL statements.

Target audiences

AudiencePain pointSolutionMessage
Web developers Quản lý media trên nhiều server, migration tốn thời gian Auto-sync, CLI, WP-Cron bg sync "Set once, automate forever"
Agency owners Dung lượng hosting tốn kém, cần CDN cho client Offload media → object storage rẻ, CDN tích hợp "Giảm 80% dung lượng hosting"
Site owners Site chậm do media từ server gốc, không có CDN URL rewriting → CDN, CloudFront, BunnyCDN "Serve media global với 1 click"
DevOps engineers Ephemeral hosting (Kinsta, Pantheon), mất media khi deploy S3-backed persistent media "Ephemeral? No problem."

Competitor comparison

Tính năngS3 Media SyncWP Offload MediaMedia Cloud
GiáFree (GPLv2)$99+/năm$49+/năm
Mã nguồn mở
S3-Compatible providers✅ Tất cảLimitedLimited
WP-CLI✅ Đầy đủ✅ Cơ bản
Background sync✅ WP-Cron
Cache purge auto✅ 5 pluginsLimitedLimited
Activity Log✅ 500 events

Content Plan & Use Cases

Ý tưởng bài viết, hướng dẫn, case study cho team Content.

Blog post ideas

Hướng dẫn

Cách đồng bộ Media WordPress lên S3 với plugin miễn phí

Hướng dẫn từ A-Z: cài đặt, cấu hình AWS S3, kích hoạt sync.

So sánh

S3 Media Sync vs WP Offload Media — Nên chọn cái nào?

So sánh tính năng, giá cả, hiệu năng. Kết luận: plugin free đủ dùng cho đa số.

Tutorial

Dùng MinIO + S3 Media Sync cho WordPress nội bộ

Hướng dẫn setup MinIO self-hosted + tích hợp với plugin.

Optimization

Giảm 80% dung lượng hosting với offload media

Case study: site 10GB media, offload lên S3, chỉ còn 2GB local.

DevOps

Automation WordPress: S3 Media Sync + WP-CLI + CI/CD

Pipeline: deploy code → sync media → purge cache, tất cả tự động.

Use case

Cloudflare R2: Zero egress fees cho media WordPress

Hướng dẫn dùng R2 làm object storage + CDN cho WordPress.

Use cases

1. Website tin tức / báo chí

Hàng nghìn hình ảnh mỗi tháng. Dùng S3 Media Sync + CDN (CloudFront) để serve ảnh global. Tiết kiệm băng thông server gốc, giảm TTFB.

2. Thương mại điện tử (WooCommerce)

Hàng trăm ảnh sản phẩm, mỗi ảnh nhiều kích thước. Offload lên S3 giúp giảm dung lượng hosting, tăng tốc product page.

3. Multisite network

5-50 sites chia sẻ media bucket. Plugin support multisite, mỗi site có thể có bucket riêng hoặc prefix riêng.

4. Agency hosting nhiều client

Mỗi client một bucket riêng. Dùng WP-CLI automation thiết lập cho site mới: clone plugin → activate → config → sync.

5. Ephemeral hosting (Kinsta, Pantheon)

Server tạm, mất file upload khi deploy. S3 Media Sync đảm bảo media persistent qua mọi deployment.

Social media posts

📱 Thread (X/Twitter) — Tính năng:

🧵 S3 Media Sync là gì?
1/ Plugin WordPress miễn phí, mã nguồn mở (GPLv2)
2/ Đồng bộ media lên AWS S3, Cloudflare R2, MinIO, iDrive E2...
3/ URL rewriting + CDN, dọn local, WP-CLI
4/ Background sync, delete sync, activity log
5/ Thay thế WP Offload Media ($99/năm) — hoàn toàn free 🆓

📘 LinkedIn — DevOps góc nhìn:

You deploy WordPress. Media lives on server. Server runs out of disk. Again.

S3 Media Sync fixes this. One plugin. Free. GPLv2.

6 CLI commands. 5 cache plugins auto-purge. 10+ S3 providers.

Built by CODE TOT for production WordPress.
👉 github.com/codetot-web/s3-media-sync

CLI Reference

Tài liệu đầy đủ về WP-CLI commands của S3 Media Sync. Yêu cầu WP-CLI.

CommandDescriptionRequires
wp s3 syncSync all unsynced attachments to S3Plugin enabled + configured
wp s3 sync --post_id=<id>Sync a single attachment by ID
wp s3 sync --batch=<n>Custom batch size (default: 10, max: 100)
wp s3 statusCheck S3 connection + config summaryPlugin configured
wp s3 delete-localDelete local files of synced mediaMedia already synced
wp s3 resetReset all sync status metadata

wp s3 sync

CORE — Process all unsynced attachments and upload to S3.

OPTIONS

OptionTypeDefaultDescription
--post_id=<id>intSync a single attachment by ID
--batch=<n>int10Number of attachments to process per batch (1–100)

EXAMPLES

# Sync all unsynced attachments
$ wp s3 sync
Syncing 1500 attachments
100% ████████████████████████████████
Success: Sync complete. Synced: 1423, Errors: 2

# Sync single attachment
$ wp s3 sync --post_id=42
Success: Synced ID 42 to bucket "my-bucket"

# Process 50 attachments per batch (faster for large libraries)
$ wp s3 sync --batch=50

wp s3 status

DIAGNOSTICS — Check plugin configuration and S3 connection.

EXAMPLES

$ wp s3 status
Status:         Enabled
Provider:       s3-compatible
Bucket:         my-media-bucket
Region:         ap-southeast-1
Endpoint:       https://s3.ap-southeast-1.idy.idrivee2.com
Success: S3 connection: OK (bucket accessible)

wp s3 delete-local

DESTRUCTIVE — Remove local file copies for attachments that have been synced. Only affects files with s3_media_sync_synced meta. Original + all resized sizes are deleted.

NOTES

  • Only processes attachments with s3_media_sync_synced meta
  • Skips files already marked with s3_media_sync_local_removed
  • Deletes original file + all sizes from wp_get_attachment_metadata()

EXAMPLES

# Delete local files for all synced attachments
$ wp s3 delete-local
Success: Deleted local files for 850 attachments.

# Verify: files should now be served from S3/CDN
$ wp s3 status
Success: S3 connection: OK (bucket accessible)

wp s3 reset

DESTRUCTIVE — Clear all sync status metadata. After reset, all attachments are treated as "not synced" and can be re-synced from scratch.

NOTES

  • Deletes s3_media_sync_synced meta from all posts
  • Deletes s3_media_sync_local_removed meta from all posts
  • Does NOT delete files from S3
  • Does NOT delete local files

EXAMPLES

# Reset then re-sync all media
$ wp s3 reset
Success: Reset complete. Cleared 1423 synced marks and 850 local removal marks.

$ wp s3 sync --batch=50
Syncing 1500 attachments
Success: Sync complete. Synced: 1500, Errors: 0

Best practices

🔄 Deployment flow

git pullcomposer installwp s3 syncwp cache flush

⏰ Nightly cron

0 3 * * * wp s3 sync --batch=50 >/dev/null 2>&1

🧪 Pre-deployment check

wp s3 status && wp s3 sync --dry-run (future)