Skip to content

Commit

Permalink
FIX: Uploads being restored into the wrong directory for multisite.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgxworld committed Sep 16, 2016
1 parent 75f3f7f commit 68637f2
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/backup_restore/restorer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_dependency "db_helper"

module BackupRestore

class RestoreDisabledError < RuntimeError; end
Expand Down Expand Up @@ -360,12 +362,32 @@ def clear_emoji_cache
def extract_uploads
if system('tar', '--exclude=*/*', '--list', '--file', @tar_filename, 'uploads')
log "Extracting uploads..."
FileUtils.cd(File.join(Rails.root, "public")) do

FileUtils.cd(@tmp_directory) do
execute_command(
'tar', '--extract', '--keep-newer-files', '--file', @tar_filename, 'uploads/',
failure_message: "Failed to extract uploadsd."
)
end

public_uploads_path = File.join(Rails.root, "public")

FileUtils.cd(public_uploads_path) do
FileUtils.mkdir_p("uploads")

tmp_uploads_path = Dir.glob(File.join(@tmp_directory, "uploads", "*")).first
previous_db_name = File.basename(tmp_uploads_path)
current_db_name = RailsMultisite::ConnectionManagement.current_db

execute_command(
'rsync', '-avp', "#{tmp_uploads_path}/", "uploads/#{current_db_name}/",
failure_message: "Failed to restore uploads."
)

if previous_db_name != current_db_name
DbHelper.remap("uploads/#{previous_db_name}", "uploads/#{current_db_name}")
end
end
end
end

Expand Down

0 comments on commit 68637f2

Please sign in to comment.