Reflection

Reflection is designed to keep your development system in sync with your production system’s files and database (by dumping). It uses a shared git repository to store these files, which allows you to mirror your production environment without the need of direct access to your production servers.

It provides two main command modes:

Get it

Reflection is a gem, hosted on Gemcutter:

  gem install gemcutter
  gem tumble
  gem install reflection

Stashing your production data

The simplest form:

  $ reflection --stash --directory /path/to/your/assets --repository git@your-shared-repository.git

This will clone git@your-shared-repository.git and add the directory /path/to/your/assets to the repository. Reflection keeps a local version of your repository in HOME/.reflection/stash. So the next time you run the command, there is no need of cloning it again.

Now, lets include a database dump

  $ reflection  --stash \
                --directory /path/to/your/assets \
                --repository git@your-shared-repository.git \
                --rails /rails/root \
                --rails-env production

This does the same as above, but additionally dumps your production database and adds the fresh dump to your repository.

I’m lazy..

You too, aren’t you? So Reflection allows you to store all command line options in a config file.

  $ reflection  --stash \
                --directory /path/to/your/assets \
                --repository git@your-shared-repository.git \
                --rails /rails/root \
                --rails-env production \
                --write /path/to/your/config

The next time you want to run the same command as above (useful for cron), you could simply call Reflection with:

  $ reflection /path/to/your/config

Getting the production stuff on your local development machine

This works exactly the same as describe above, but you would use --apply instead of --stash:

  $ reflection  --apply \
                --directory /path/to/your/assets \
                --repository git@your-shared-repository.git \
                --rails /rails/root \
                --rails-env development

This clones or pulls git@your-shared-repository.git (again, Reflection keeps a version of your Repository in HOME/.reflection/apply), copies the content to the specified directory (e.g. rails/application/public/assets) and optionally loads the dump into your database.

As you may have noticed, the Reflection command above got called with --rails-env development, which loads the dump in your development database (as defined by /rails/root/config/database.yml).

A little productivity hint

If you have a reflection.yml config file in your current application-development-directory, syncing your server-production environment is as easy as running:

  $ reflection

reflection --help

  $ reflection --help
  Usage: reflection --COMMAND --repository=GIT_REPO --directory=PATH
   -or-
  Usage: reflection /path/to/reflection-config-file.yml

  On the server side:
      -s, --stash                      Store your assets and/or a database dump in a git-repository.
  On the client side:
      -a, --apply                      Apply assets and/or a database dump loaded from a git-repository.

  Required options for both:
      -r, --repository GIT_URL         A Git repository(url) to be used as storage
      -d, --directory PATH             Path to your asset directory

  Additional options for both:
          --rails [RAILS_ROOT]         Enable dumping/applying of a Rails managed MySQL database
          --rails-env [ENV]            Rails environment to instrument
          --write [FILE]               Create a configuration FILE from the current commandline options

Note on Patches/Pull Requests

Copyright

Copyright © 2009 Andreas Wolff. See LICENSE for details.