Sync your rails development environment data with production or staging

When your developing a web app, you usually end up with lots of duff data both in your database and file system from when you have been testing inserting data and uploading files when things have been half implemented. Usually its a good idea to take a fresh database dump from your production server and download the assets (or whatever you call the directory where user uploads go) so that you actually have some real data.

This is usually a bit of a pain to do as you need to ssh in to dump the database, SCP the assets. It also forces you to develop using a MySQL database if thats what your production server uses.

Adam Wiggins has released a plugin called yaml_db that allows you to dump and import your database into/from YAML format. Today I wrote a quick rake task that connects to your production or staging over SSH, runs the task to dump the YAML file (rake db:data:dump) and then downloads it locally with SFTP. It then runs the rake task to import the data (rake db:data:load). It also uses Rsync to sync any asset or other folders on your remote server that are installation specific to your local development environment.

At the moment the only downside to the script is that it calls rsync from the shell which asks you to type your password. It would be good to have it all inclusive within the script, but that doesn’t seem possible with rsync. The script is a gist on Github

Posted by Matt Sun, 01 Mar 2009 14:51:00 GMT


Comments

  1. Avatar
    Paul Horsfall 12 days later:

    I guess the easy fix to been prompted for the password is to set up your SSH keys.