mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 20:44:40 +08:00
FEATURE: Migrate uploads to S3 during restore
This commit is contained in:
@ -345,6 +345,7 @@ def migrate_to_s3
|
||||
end
|
||||
|
||||
bucket_has_folder_path = true if ENV["DISCOURSE_S3_BUCKET"].include? "/"
|
||||
public_directory = Rails.root.join("public").to_s
|
||||
|
||||
opts = {
|
||||
region: ENV["DISCOURSE_S3_REGION"],
|
||||
@ -369,7 +370,7 @@ def migrate_to_s3
|
||||
print " - Listing local files"
|
||||
|
||||
local_files = []
|
||||
IO.popen("cd public && find uploads/#{db}/original -type f").each do |file|
|
||||
IO.popen("cd #{public_directory} && find uploads/#{db}/original -type f").each do |file|
|
||||
local_files << file.chomp
|
||||
putc "." if local_files.size % 1000 == 0
|
||||
end
|
||||
@ -398,7 +399,7 @@ def migrate_to_s3
|
||||
|
||||
skip_etag_verify = ENV["SKIP_ETAG_VERIFY"].present?
|
||||
local_files.each do |file|
|
||||
path = File.join("public", file)
|
||||
path = File.join(public_directory, file)
|
||||
name = File.basename(path)
|
||||
etag = Digest::MD5.file(path).hexdigest unless skip_etag_verify
|
||||
key = file[file.index(prefix)..-1]
|
||||
@ -534,7 +535,7 @@ def migrate_to_s3
|
||||
.where("u.id IS NOT NULL AND u.url LIKE '//%' AND optimized_images.url NOT LIKE '//%'")
|
||||
.delete_all
|
||||
|
||||
puts "Flagging all posts containing oneboxes for rebake..."
|
||||
puts "Flagging all posts containing lightboxes for rebake..."
|
||||
|
||||
count = Post.where("cooked LIKE '%class=\"lightbox\"%'").update_all(baked_version: nil)
|
||||
puts "#{count} posts were flagged for a rebake"
|
||||
|
Reference in New Issue
Block a user