Saturday, October 1, 2011

Postgres/MySQL database synchronization using RubyRep



It is nice to have a tool which can synchronize two databases so that if you have two copies of a database then you can convert the old database to the latest one, by synchronizing all the missing data to new database. A synchronization tool makes database A same as database B provided that A and B has the same schema. The tool does this by copying all extra data in A to B and deleting extra data in B. One practical use of such a tool is synchronizing a production database to staging database and vice versa.

Database systems like Oracle comes with built in tools to sync two datbases but postgres and mysql does not have a sync tool in its default package. So if you want to synchronize two postgres databases then you require a third party tool. RubyRep is such a synchronization tool which supports postgres and mysql. As the name indicates it is developed using Ruby language, that means you have to install ruby in your machine to use this tool. It also requires a number of gems (ruby libraries), but wait.... Rubyrep also has a Jruby version, that means you can run it on any machine which has a JVM installed on it and you dont have to install any dependencies. Cool, isn't it? All you have to do is to download it, extract it and use it. Here is the home page of RubyRep

A simple guide to using RubyRep

Rubyrep works on the following concepts....
It has to synchronize two databases; the left database and the right database.By default it synchronizes left database to right database. You have to provide the list of tables which has to be synchronized. Ruby rep assumes that your tables are in public schema. If you have other schemas then you have to provide the schma name also. Rubyrep reads the left and right database connection details and other configurations from a config file. The configuration file has its own syntax.So the best way to create a config file is to allow ruby rep to create a default config file, then edit it with your database details.
  1. Creating a config file
rubyrep create CONFIG_FILE
eg: sh rubyrep create myconf.cfg

  1. Scanning difference between two databases
rubyrep scan -c CONFIG_FILE
eg: sh rubyrep scan -c myconf.cfg

  1. Syncing two databases
rubyrep sync -c CONFIG_FILE
eg:sh rubyrep sync -c myconf.cfg

  1. Overwrting the default configurations
To overwrite the configuration in the config file, pass the configuration parameters as arguements to the rubyrep command
eg: rubyrep sync -c alert_manager.cfg 'vertical_lv',tip
Synchronizes only vertical_lv and tip tables
For more details, visit the rubyrep tutorial page.

No comments:

Post a Comment