不同环境之间的快速,安全地同步数据:pgsync

jopen 8年前

pgsync

不同环境之间的快速,安全地同步数据

Installation

gem install pgsync

And in your project directory, run:

pgsync setup

This creates a.pgsync.ymlfor you to customize. We recommend checking this into your version control (assuming it doesn’t contain sensitive information).

How to Use

Fetch all tables

pgsync

Fetch specific tables

pgsync table1,table2

Fetch specific rows (truncates destination table first)

pgsync products --where "id < 100"

Exclude Tables

pgsync --exclude users

To always exclude, add to.pgsync.yml.

exclude: - table1 - table2

For Rails, you probably want to exclude schema migrations.

exclude: - schema_migrations

Schema

Fetch schema

pgsync schema

Specify tables

pgsync schema table1,table2

Groups

Define groups in.pgsync.yml:

groups: group1: - table1 - table2 group2: - table3 - table4

And run:

pgsync groups group1,group2

Sensitive Information

Prevent sensitive information - like passwords and email addresses - from leaving the remote server.

Define rules in.pgsync.yml:

data_rules:    email: unique_email    last_name: random_letter    birthday: random_date    users.auth_token:      value: secret    visits_count:      statement: "(RANDOM() * 10)::int"    encrypted_*: null

last_namematches all columns namedlast_nameandusers.last_namematches only the users table. Wildcards are supported, and the first matching rule is applied.

Options for replacement are:

  • null
  • value
  • statement
  • unique_email
  • unique_phone
  • random_letter
  • random_int
  • random_date
  • random_time
  • random_ip
  • untouched

Safety

To keep you from accidentally overwriting production, the destination is limited tolocalhostor127.0.0.1by default.

To use another host, addto_safe: trueto your.pgsync.yml.

项目主页:http://www.open-open.com/lib/view/home/1449998494906