Migrate_to_S3 Fails on Rebake

With the help of @itsbhanusharma, I’ve been working to move my old uploads over to S3.

I followed the steps in this guide:

After a rebuild, the uploads sitll had not moved to S3, which is odd. Discourse-doctor reported a DNS problem:

> 
> ========================================
> Discourse version at : NOT FOUND
> Discourse version at localhost: Discourse 2.5.0.beta4
> **> ==================== DNS PROBLEM ====================**
> **> This server reports Discourse 2.5.0.beta4 , but reports NOT FOUND.**
> **> This suggests that you have a DNS problem or that an intermediate proxy is to blame.**
> **> If you are using Cloudflare, or a CDN, it may be improperly configured.**

I ran a manual migrate to S3 and got the following:

 > root@discourse-app:/var/www/discourse# rake --trace uploads:migrate_to_s3
> ** Invoke uploads:migrate_to_s3 (first_time)
> ** Invoke environment (first_time)
> ** Execute environment
> ** Execute uploads:migrate_to_s3
> Migrating uploads to S3 for 'default'...
> Uploading files to S3...
>  - Listing local files
> .. => 2980 files
>  - Listing S3 files
> .... => 3156 files
>  - Syncing files to S3
> ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
> Updating the URLs in the database...
> Warning: no type cast defined for type "name" with oid 19. Please cast this type explicitly to TEXT to be safe for future changes.
> Removing old optimized images...
> Flagging all posts containing lightboxes for rebake...
> 781 posts were flagged for a rebake
> rake aborted!
> FileStore::ToS3MigrationError: 68 posts are not remapped to new S3 upload URL. S3 migration failed for db 'default'.
> /var/www/discourse/lib/file_store/to_s3_migration.rb:131:in `raise_or_log'
> /var/www/discourse/lib/file_store/to_s3_migration.rb:86:in `migration_successful?'
> /var/www/discourse/lib/file_store/to_s3_migration.rb:351:in `migrate_to_s3'
> /var/www/discourse/lib/file_store/to_s3_migration.rb:65:in `migrate'
> /var/www/discourse/lib/tasks/uploads.rake:239:in `migrate_to_s3'
> /var/www/discourse/lib/tasks/uploads.rake:218:in `block in migrate_to_s3_all_sites'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rails_multisite-2.1.2/lib/rails_multisite/connection_management.rb:64:in `with_connection'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rails_multisite-2.1.2/lib/rails_multisite/connection_management.rb:74:in `each_connection'
> /var/www/discourse/lib/tasks/uploads.rake:216:in `migrate_to_s3_all_sites'
> /var/www/discourse/lib/tasks/uploads.rake:212:in `block in <top (required)>'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `block in execute'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `each'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:281:in `execute'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
> /usr/local/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:188:in `invoke'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:160:in `invoke_task'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `each'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block in top_level'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:125:in `run_with_threads'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:110:in `top_level'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:83:in `block in run'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:80:in `run'
> bin/rake:13:in `<top (required)>'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
> /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
> /usr/local/bin/bundle:23:in `load'
> /usr/local/bin/bundle:23:in `<main>'
> Tasks: TOP => uploads:migrate_to_s3
> root@discourse-app:/var/www/discourse#

Any thoughts on this @gerhard?

It fails because the following check fails:

I suggest you find out why those paths aren’t remapped correctly. Try running the following in the rails console to look at cooked of those posts. Somewhere in there might be a clue…

current_db = RailsMultisite::ConnectionManagement.current_db
cdn_path = SiteSetting.cdn_path("/uploads/#{current_db}/original").sub(/https?:/, "")
Post.where("cooked LIKE '%#{cdn_path}%'").pluck(:cooked)
3 Likes

Here’s the output from the rails console: (this is only part of it and it is ugly)

root@discourse-app:/var/www/discourse# rails console
[1] pry(main)> current_db = RailsMultisite::ConnectionManagement.current_db
=> "default"
[2] pry(main)> cdn_path = SiteSetting.cdn_path("/uploads/#{current_db}/original").sub(/https?:/, "")
=> "/uploads/default/original"
[3] pry(main)> Post.where("cooked LIKE '%#{cdn_path}%'").pluck(:cooked)
=> ["<p>U.C. Tricolor frag $30<br>\nRed Stylocoeniella $30<br>\nBranching Cyphastrea $40<br>\nOrenji Mont frag $30</p>\n<hr>\n<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"//brcuploads.s3.dualstack.us-east-1.amazonaws.com/original/2X/2/282821b1e16dce48ac11f1d607412e1bfed61534.jpeg\" data-download-href=\"/uploads/short-url/5Jf4Z7WaQqYix5IDWN12IlLoYfi.jpeg?dl=1\" title=\"DSCN0069-005.JPG\"><img src=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/2/282821b1e16dce48ac11f1d607412e1bfed61534_2_524x500.jpeg\" alt=\"DSCN0069-005.JPG\" data-base62-sha1=\"5Jf4Z7WaQqYix5IDWN12IlLoYfi\" width=\"524\" height=\"500\" srcset=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/2/282821b1e16dce48ac11f1d607412e1bfed61534_2_524x500.jpeg, https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/2/282821b1e16dce48ac11f1d607412e1bfed61534_2_786x750.jpeg 1.5x, /uploads/default/original/2X/2/282821b1e16dce48ac11f1d607412e1bfed61534.jpeg 2x\" data-small-upload=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/2/282821b1e16dce48ac11f1d607412e1bfed61534_2_10x10.png\"><div class=\"meta\"><svg class=\"fa d-icon d-icon-far-image svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#far-image\"></use></svg><span class=\"filename\">DSCN0069-005.JPG</span><span class=\"informations\">800×762 181 KB</span><svg class=\"fa d-icon d-icon-discourse-expand svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#discourse-expand\"></use></svg></div></a></div></p>\n<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"//brcuploads.s3.dualstack.us-east-1.amazonaws.com/original/2X/9/960e0f184917ad7e0bbf2d6c31cf546fa9e124f5.jpeg\" data-download-href=\"/uploads/short-url/lprJZk3t4LfijslovcQ9kgaqzcN.jpeg?dl=1\" title=\"DSCN0119-003.JPG\"><img src=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/9/960e0f184917ad7e0bbf2d6c31cf546fa9e124f5_2_513x500.jpeg\" alt=\"DSCN0119-003.JPG\" data-base62-sha1=\"lprJZk3t4LfijslovcQ9kgaqzcN\" width=\"513\" height=\"500\" srcset=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/9/960e0f184917ad7e0bbf2d6c31cf546fa9e124f5_2_513x500.jpeg, https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/9/960e0f184917ad7e0bbf2d6c31cf546fa9e124f5_2_769x750.jpeg 1.5x, /uploads/default/original/2X/9/960e0f184917ad7e0bbf2d6c31cf546fa9e124f5.jpeg 2x\" data-small-upload=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/9/960e0f184917ad7e0bbf2d6c31cf546fa9e124f5_2_10x10.png\"><div class=\"meta\"><svg class=\"fa d-icon d-icon-far-image svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#far-image\"></use></svg><span class=\"filename\">DSCN0119-003.JPG</span><span class=\"informations\">800×779 186 KB</span><svg class=\"fa d-icon d-icon-discourse-expand svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#discourse-expand\"></use></svg></div></a></div></p>\n<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"//brcuploads.s3.dualstack.us-east-1.amazonaws.com/original/2X/5/548f0324f3b0e8dd482729c1d1f5c450b5556919.jpeg\" data-download-href=\"/uploads/short-url/c42vC8e8IRT52htW2RX7YedLpaN.jpeg?dl=1\" title=\"DSCN0072-004.JPG\"><img src=\"//brcuploads.s3.dualstack.us-east-1.amazonaws.com/original/2X/5/548f0324f3b0e8dd482729c1d1f5c450b5556919.jpeg\" alt=\"DSCN0072-004.JPG\" data-base62-sha1=\"c42vC8e8IRT52htW2RX7YedLpaN\" width=\"468\" height=\"500\" data-small-upload=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/5/548f0324f3b0e8dd482729c1d1f5c450b5556919_2_10x10.png\"><div class=\"meta\"><svg class=\"fa d-icon d-icon-far-image svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#far-image\"></use></svg><span class=\"filename\">DSCN0072-004.JPG</span><span class=\"informations\">750×800 180 KB</span><svg class=\"fa d-icon d-icon-discourse-expand svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#discourse-expand\"></use></svg></div></a></div></p>\n<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"//brcuploads.s3.dualstack.us-east-1.amazonaws.com/original/2X/d/dc75e2b57072ff260f99cfa9a7cc1e4f39c207f8.jpeg\" data-download-href=\"/uploads/short-url/vshBXgkYrsRhRqNFakI1jgIE5Sg.jpeg?dl=1\" title=\"DSCN0060-005.JPG\"><img src=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/d/dc75e2b57072ff260f99cfa9a7cc1e4f39c207f8_2_396x500.jpeg\" alt=\"DSCN0060-005.JPG\" data-base62-sha1=\"vshBXgkYrsRhRqNFakI1jgIE5Sg\" width=\"396\" height=\"500\" srcset=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/d/dc75e2b57072ff260f99cfa9a7cc1e4f39c207f8_2_396x500.jpeg, https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/d/dc75e2b57072ff260f99cfa9a7cc1e4f39c207f8_2_594x750.jpeg 1.5x, /uploads/default/original/2X/d/dc75e2b57072ff260f99cfa9a7cc1e4f39c207f8.jpeg 2x\" data-small-upload=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/d/dc75e2b57072ff260f99cfa9a7cc1e4f39c207f8_2_10x10.png\"><div class=\"meta\"><svg class=\"fa d-icon d-icon-far-image svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#far-image\"></use></svg><span class=\"filename\">DSCN0060-005.JPG</span><span class=\"informations\">635×800 196 KB</span><svg class=\"fa d-icon d-icon-discourse-expand svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#discourse-expand\"></use></svg></div></a></div></p>",
 "<p>U.C. Raspberry delight frag $39 “radion”<br>\nORA Kelly green psammacora $39 \"radion<br>\nU.C. Red Dragon Frag $30<br>\nU.C. Red dragon Smaller frag $20</p>\n<hr>\n<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"//brcuploads.s3.dualstack.us-east-1.amazonaws.com/original/2X/d/deb035a3639a3a3bb8b04ebd9da2b97fb5d8652d.jpeg\" data-download-href=\"/uploads/short-url/vLZwAqgUqcslrwos7Q27gheEVSR.jpeg?dl=1\" title=\"DSCN9908-003.JPG\"><img src=\"//brcuploads.s3.dualstack.us-east-1.amazonaws.com/original/2X/d/deb035a3639a3a3bb8b04ebd9da2b97fb5d8652d.jpeg\" alt=\"DSCN9908-003.JPG\" data-base62-sha1=\"vLZwAqgUqcslrwos7Q27gheEVSR\" width=\"561\" height=\"500\" data-small-upload=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/d/deb035a3639a3a3bb8b04ebd9da2b97fb5d8652d_2_10x10.png\"><div class=\"meta\"><svg class=\"fa d-icon d-icon-far-image svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#far-image\"></use></svg><span class=\"filename\">DSCN9908-003.JPG</span><span class=\"informations\">800×712 165 KB</span><svg class=\"fa d-icon d-icon-discourse-expand svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#discourse-expand\"></use></svg></div></a></div></p>\n<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"//brcuploads.s3.dualstack.us-east-1.amazonaws.com/original/2X/e/e579dab30a023f12755b22e8bb1c077b34225110.jpeg\" data-download-href=\"/uploads/short-url/wK2pz5DNtgezJhhQuxaFE52CvnO.jpeg?dl=1\" title=\"DSCN0059-005.JPG\"><img src=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/e/e579dab30a023f12755b22e8bb1c077b34225110_2_450x500.jpeg\" alt=\"DSCN0059-005.JPG\" data-base62-sha1=\"wK2pz5DNtgezJhhQuxaFE52CvnO\" width=\"450\" height=\"500\" srcset=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/e/e579dab30a023f12755b22e8bb1c077b34225110_2_450x500.jpeg, https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/e/e579dab30a023f12755b22e8bb1c077b34225110_2_675x750.jpeg 1.5x, /uploads/default/original/2X/e/e579dab30a023f12755b22e8bb1c077b34225110.jpeg 2x\" data-small-upload=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/e/e579dab30a023f12755b22e8bb1c077b34225110_2_10x10.png\"><div class=\"meta\"><svg class=\"fa d-icon d-icon-far-image svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#far-image\"></use></svg><span class=\"filename\">DSCN0059-005.JPG</span><span class=\"informations\">721×800 231 KB</span><svg class=\"fa d-icon d-icon-discourse-expand svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#discourse-expand\"></use></svg></div></a></div></p>\n<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"//brcuploads.s3.dualstack.us-east-1.amazonaws.com/original/2X/e/e5d72072aee537852120d7106522b543e6af9085.jpeg\" data-download-href=\"/uploads/short-url/wNgfm2qrVEyTWGfUV3QAc2EGKfX.jpeg?dl=1\" title=\"DSCN0066-005.JPG\"><img src=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/e/e5d72072aee537852120d7106522b543e6af9085_2_506x500.jpeg\" alt=\"DSCN0066-005.JPG\" data-base62-sha1=\"wNgfm2qrVEyTWGfUV3QAc2EGKfX\" width=\"506\" height=\"500\" srcset=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/e/e5d72072aee537852120d7106522b543e6af9085_2_506x500.jpeg, https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/e/e5d72072aee537852120d7106522b543e6af9085_2_759x750.jpeg 1.5x, /uploads/default/original/2X/e/e5d72072aee537852120d7106522b543e6af9085.jpeg 2x\" data-small-upload=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/e/e5d72072aee537852120d7106522b543e6af9085_2_10x10.png\"><div class=\"meta\"><svg class=\"fa d-icon d-icon-far-image svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#far-image\"></use></svg><span class=\"filename\">DSCN0066-005.JPG</span><span class=\"informations\">800×790 200 KB</span><svg class=\"fa d-icon d-icon-discourse-expand svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#discourse-expand\"></use></svg></div></a></div></p>\n<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"//brcuploads.s3.dualstack.us-east-1.amazonaws.com/original/2X/3/3cd28b0f2704180632ca5e714241b6b62f63459e.jpeg\" data-download-href=\"/uploads/short-url/8G3Jz9KwzbbXzYx3PYei4ayTmSa.jpeg?dl=1\" title=\"DSCN0068-005.JPG\"><img src=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/3/3cd28b0f2704180632ca5e714241b6b62f63459e_2_395x500.jpeg\" alt=\"DSCN0068-005.JPG\" data-base62-sha1=\"8G3Jz9KwzbbXzYx3PYei4ayTmSa\" width=\"395\" height=\"500\" srcset=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/3/3cd28b0f2704180632ca5e714241b6b62f63459e_2_395x500.jpeg, https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/3/3cd28b0f2704180632ca5e714241b6b62f63459e_2_592x750.jpeg 1.5x, /uploads/default/original/2X/3/3cd28b0f2704180632ca5e714241b6b62f63459e.jpeg 2x\" data-small-upload=\"https://d2hneyr8lp58j4.cloudfront.net/optimized/2X/3/3cd28b0f2704180632ca5e714241b6b62f63459e_2_10x10.png\"><div class=\"meta\"><svg class=\"fa d-icon d-icon-far-image svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#far-image\"></use></svg><span class=\"filename\">DSCN0068-005.JPG</span><span class=\"informations\">633×800 139 KB</span><svg class=\"fa d-icon d-icon-discourse-expand svg-icon\" aria-hidden=\"true\"><use xlink:href=\"#discourse-expand\"></use></svg></div></a></div></p>",

I think I fixed the issue. I noticed I couldn’t run a backup and eventually found that the backup bucket name was spelled wrong in app.yml. The upload bucket was fine. I fixed the spelling and backups worked again. Just tried this for giggles and it went through.

Running a rebake on the posts right now.

2 Likes