app/controllers/admin_controller.rb
#
# Dumps database using mysqldump and sends dump file to browser
# The dump is created in memory
#
Dumps database using mysqldump and sends dump file to browser
The dump is created in memory
Dumps database using mysqldump and sends dump file to browser The dump is created in memory
def dump
    dump = StringIO.new
    filename = "dump-" + Date.today.to_s + ".sql"
    database = ActiveRecord::Base.configurations[RAILS_ENV]['database']
    username = ActiveRecord::Base.configurations[RAILS_ENV]['username']
    password = ActiveRecord::Base.configurations[RAILS_ENV]['password']
    if password.nil?
      dump.write(`mysqldump -u #{username} #{database}`)
    else
      dump.write(`mysqldump -u #{username} -p#{password} #{database}`)
    end
    dump.rewind    
    send_data(dump.read,
      :type => 'text/plain; charset=utf-8; header=present',
      :filename => filename)
  end
def dump dump = StringIO . new filename = "dump-" + Date . today . to_s + ".sql" database = ActiveRecord :: Base . configurations [ RAILS_ENV ] [ 'database' ] username = ActiveRecord :: Base . configurations [ RAILS_ENV ] [ 'username' ] password = ActiveRecord :: Base . configurations [ RAILS_ENV ] [ 'password' ] if password . nil? dump . write ( ` mysqldump -u  #{ username } #{ database } ` ) else dump . write ( ` mysqldump -u  #{ username }  -p #{ password } #{ database } ` ) end dump . rewind send_data ( dump . read , :type => 'text/plain; charset=utf-8; header=present' , :filename => filename ) end
Dumps database using mysqldump and sends dump file to browser
The dump is created in memory
Dumps database using mysqldump and sends dump file to browser The dump is created in memory