不同環境之間的快速,安全地同步數據:pgsync

jopen 8年前發布 | 7K 次閱讀 pgsync Android開發 移動開發

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.baiduhome.net/lib/view/home/1449998494906

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!