migrate_photos_to_remote command migrates photos from local filesystem storage to remote cloud storage (AWS S3 or Cloudflare R2). This is useful when transitioning from local development to production with cloud storage.
How it works
The command reads photos from the local filesystem and uploads them to the configured remote storage backend while maintaining the same file paths and structure.Basic usage
Arguments and options
Preview mode - show what would be migrated without actually uploading files.Example:
Show detailed output including each file being processed.Example:
Skip photos that already exist in remote storage (avoids re-uploading).Example:
Prerequisites
Configure remote storage
Set the storage backend in your environment:AWS S3 configuration
Cloudflare R2 configuration
Migration workflow
Verify storage configuration
Ensure remote storage credentials are correct and the bucket is accessible.
What gets migrated
The command migrates all files in the Photo model:- Original images:
imagefield (JPEG/PNG/WebP) - AVIF versions:
image_aviffield (optimized format)
Output example
Resume interrupted migration
If migration is interrupted, resume with--skip-existing:
Storage validation
Before migration, the command validates:- Storage backend is set to remote (
s3orr2) - Remote storage credentials are configured
- Bucket is accessible
Performance considerations
- Upload speed: Depends on network bandwidth and file sizes
- Large migrations: For thousands of photos, consider running in a screen/tmux session
- Bandwidth costs: Check your cloud provider’s transfer pricing
Troubleshooting
Storage backend error
Storage backend error
Ensure Not
STORAGE_BACKEND is set to s3 or r2:local.Authentication failed
Authentication failed
Verify credentials are correct:
Bucket not found
Bucket not found
Verify bucket name and region:Ensure the bucket exists in your cloud provider console.
Files not uploading
Files not uploading
Check file permissions on local files:Ensure the Django process has read access.
Slow upload speed
Slow upload speed
For large migrations, consider:
- Running during off-peak hours
- Using a cloud instance in the same region as your bucket
- Increasing network bandwidth
Post-migration
After successful migration:- Update settings: Ensure
STORAGE_BACKENDis set in production environment - Test uploads: Create a new item with photos to verify new uploads work
- Monitor storage: Check cloud storage usage and costs
- Backup: Consider keeping local files as backup temporarily