class DatabaseController < ApplicationController def database_dump database = Rails.configuration.database_configuration[Rails.env]["database"] send_file_headers!(:type => 'application/octet-stream', :filename => "#{database}_#{Time.now.to_s(:human)}.backup") pipe = IO.popen("pg_dump '#{database}' -F c") stream = response.stream while (line = pipe.gets) stream.write line Thread.pass # per https://gist.github.com/njakobsen/6257887#gistcomment-1235792 end rescue IOError # Client Disconnected ensure pipe.close response.stream.close end # Code that allows us to only mix in the live methods if we're accessing the desired action def dispatch(name, *args) extend ActionController::Live if name.to_s == 'database_dump' super end end