Themigrator

The migrator is a program that eases and automates data migrations.

Installation

Install it as a normal gem

$ gem install themigrator

Usage

themigrator helps a data migration by automating a pre-defined process.

It uses the concepts of roles(folders), and actions(scripts).

Each role can contain any file, but themigrator will treat some of them in a special way.

This is the list of actions and its intended behaviour:

  • setup Provision machines with tooling or opening tunnels.
  • pre-migrate Put the site in maintenance mode.
  • migrate Copy data and check integrity.
  • cleanup In case migrate works, it will cleanup, or enable a site.
  • rollback In case any previous command fails, rollback is called.

There are some constrains:

  • All the actions are called at the same time for all the roles.
  • Unless all the actions return a 0, the next action is not executed.
  • In case an action return a non zero code, a SIGINT is sent to the rest of the actions still alive.
  • If case an action return a non zero code, the rollback script will be called only for the roles that run any previous action.

Example

For example. We have three roles: mariadb, redis, and app.

/mariadb/setup         # Check maria is still app and running.
/mariadb/pre-migrate   # Disable inserts.
/mariadb/migrate       # Run `ssh oldmaria mysqldump | mysql newmaria`.
/mariadb/cleanup       # Stop mariadb.
/mariadb/rollback      # Enable inserts.
/redis/migrate         # Run `redis-cli oldredis dump | redis-cli newredis bullread`.
/app/pre-migrate       # Set maintenance mode and stop the app servers.
/app/rollback          # Enable the old site

Will do the following:

  1. Run the mariadb/setup. If fails mariadb/rollback
  2. Run the mariadb/pre-migrate and app/pre-migrate. If fails mariadb/rollback and app/rollback.
  3. Run the mariadb/migrate and redis/migrate. If fails mariadb/rollback and app/rollback.
  4. Run the mariadb/cleanup. Will output the error.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/wooga/themigrator.