acromedia/database-janitor

数据库消毒剂、修剪器和清洁器。

1.1.0 2019-07-31 16:33 UTC

This package is not auto-updated.

Last update: 2024-09-15 17:01:50 UTC


README

由Acro Media Inc.资助的初始开发。

Database Janitor 构建状态

高度可配置的数据库导出工具

由Acro Media Inc.资助的初始开发。

特性

  • Drupal配置支持
  • 以配置为主
  • PHP,依赖最少

用法

此应用程序可以作为CLI应用程序使用,也可以作为其他应用程序可以构建在其上的库,例如drush命令或另一个自定义应用程序。

命令帮助

Description:
  Cleans up databases between servers or dev enviornments

Usage:
  database-janitor [options] [--] <database>

Arguments:
  database                   Database to dump

Options:
      --host[=HOST]          Database host, defaults to localhost
  -u, --username[=USERNAME]  Database username
  -p, --password[=PASSWORD]  Database password
  -t, --trim                 Whether or not to exclude data from dump (trimming)
  -d, --drupal=DRUPAL        Path to a Drupal settings file (ignores host, username and password flags)
  -h, --help                 Display this help message
  -q, --quiet                Do not output any message
  -V, --version              Display this application version
      --ansi                 Force ANSI output
      --no-ansi              Disable ANSI output
  -n, --no-interaction       Do not ask any interactive question
  -v|vv|vvv, --verbose       Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

测试

您可以使用一个示例Lando配置来启动两个独立的MySQL数据库进行测试,以及一个包含由Mockaroo生成的随机数据的示例SQL文件。

lando start
lando db-import sampledata.sql --host real_database

配置

sanitize_tables:
  # List of tables and their columns you want sanitized.
  user:
  - mail
trim_tables:
# List of tables to be trimmed (every 4th row kept)
  - trim1
excluded_tables:
# Tables to NOT dump
  - exclude1
scrub_tables:
# Tables to dump sans content.
  - scrub1
keep_data:
# Keep data in these tables by key
  table_name:
    col: col_name
    # Only row with col value of 1
    rows:
      - 1
  table_name_2:
  # Every other row, using mod
    col: other_col_name
    rows: 2

  table_name_3:
  # Every row with a value of 1, 3 or 8.
    col: third_col_name
    rows: 1, 3, 8

CLI

首先,您需要将.janitor.example.yml复制到.janitor.yml。然后您可以进入并编辑您想要消毒/忽略/清除的确切表和列。

如果不使用.phar,请使用composer install安装依赖项。

导出

这将提示您输入数据库密码,然后在output/目录中生成一个gzip的.sql文件。

./janitor.phar --host=localhost:8787 --username=real real | gzip -c > output/real_test.sql.gz

修剪

通过保留数据、清洁表等减少导出数据,修剪可以使数据库导出更小。

./janitor.phar --host=localhost:8787 --username=real --trim real | gzip -c > output/real_test.sql.gz