Migrating uploads (images, videos, files) from a Linux server to AWS S3

Thanks @JaviRuiz for the insights with the formats field. I had to adapt the request to my PostgreSQL database, so in case anyone needs it someday here are the requests I used:

Update other formats urls (couldn’t manage to do it in one request so here are all of them). YOUR_BUCKET_URL must end with /

UPDATE files 
SET formats = jsonb_set(formats, '{thumbnail,url}', concat('"', YOUR_BUCKET_URL, 'thumbnail_', hash, ext, '"')::jsonb)
WHERE formats IS NOT NULL;

UPDATE files 
SET formats = jsonb_set(formats, '{small,url}', concat('"', YOUR_BUCKET_URL, 'small_', hash, ext, '"')::jsonb)
WHERE formats IS NOT NULL;

UPDATE files 
SET formats = jsonb_set(formats, '{medium,url}', concat('"', YOUR_BUCKET_URL, 'medium_', hash, ext, '"')::jsonb)
WHERE formats IS NOT NULL;

UPDATE files 
SET formats = jsonb_set(formats, '{large,url}', concat('"', YOUR_BUCKET_URL, 'large_', hash, ext, '"')::jsonb)
WHERE formats IS NOT NULL;

Update url field:

UPDATE files SET url=concat(YOUR_BUCKET_URL, hash, ext);

Update provider field:

UPDATE files SET provider='aws-s3';

With those 3 steps, you should be good to go!

1 Like