# Getting Local Development Data for Rails from Your Production Site using Heroku

DevFeed: [Getting Local Development Data for Rails from Your Production Site using Heroku](<https://devfeed.tech/articles/getting-local-development-data-for-rails-from-your-production-site-using-heroku-28244.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/rails/2019/11/16/getting-local-development-data-for-rails-from-your-production-site-using-heroku.html>)

Author: Fuzzygroup

Published: 2019-11-16T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [Heroku](<https://devfeed.tech/topics/heroku.md>), [MySQL](<https://devfeed.tech/topics/mysql.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [backup](<https://devfeed.tech/tags/backup.md>), [database](<https://devfeed.tech/tags/database.md>), [heroku](<https://devfeed.tech/tags/heroku.md>), [mysql](<https://devfeed.tech/tags/mysql.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rake](<https://devfeed.tech/tags/rake.md>), [test-coverage](<https://devfeed.tech/tags/test-coverage.md>)

## AI overview

A tutorial explaining how to copy production data from a Heroku-hosted Rails application into a local development environment. It uses MySQL export and import commands, recommends backing up local data first, and provides a Rake task to simplify the workflow.

## Source excerpt

One of the worst aspects of doing Rails development, although this is not limited to Rails in any way, is getting data to use for development work once your site starts getting users. Yes I know that you should always have full test coverage and that local data shouldn't be necessary - but it absolutely is. There is always a class of errors that you simply can't diagnose with a set of data with which to work. The happy truth though is that you actually can pretty easily move data from production to development at will (at least as long as the database isn't too massive; when your site gets large it is a different matter). The Approach The approach here is actually pretty simple. My examples all center around using MySQL as a data store but any database that has solid import / export will work. To start you should backup your local data just in case you need it back afterwards. You then connect to your remote datastore and use mysqldump to export your data to a local data dump. You then import this local data dump. You debug your site using a much richer set of data. Making this Easy with a Rake Task Here's a rake task that I wrote that gives you a lot of tasks for dealing with your local / remote databases. Drop this into lib/tasks and you can see the tasks it offers with: bundle exec rake -T | grep database namespace :database do namespace :development do # Generates a mysql load command # bundle exec rake database:development:mysql_load_data_command --trace task :mysql_load_data_command => :environment do #username, password, database db_params = get_local_database_params command = make_mysql_command('mysql', db_params, ' < lib/tasks/data/db_dumps/') puts "Add the load file into the below command " puts " once you copy and paste it back into the terminal" puts command end # generates a mysql command to get into the database # bundle exec rake database:development_mysql_command --trace task :mysql_command => :environment do db_params = get_local_database_params com