Giter Site home page Giter Site logo

zeip / database-janitor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gmemstr/database-janitor

0.0 1.0 0.0 164 KB

custommized database dumps, with native drupal configuration support

License: Mozilla Public License 2.0

PHP 96.39% Dockerfile 3.61%

database-janitor's Introduction

Initial development funded by Acro Media Inc.

Database Janitor Build Status

Highly-configurable database dumper

Initial development funded by Acro Media Inc.

Features

  • Drupal configuration support
  • Configuration-first
  • PHP with minimal dependencies

Usage

This application can either be used as a CLI app or a library that other applications can build on top of, e.g a drush command or another custom application.

Command Help

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

Testing

There is a sample Lando config you can use to spin up two separate mysql databases for testing, as well as a sample SQL file containing random data generated by Mockaroo.

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

Configuration

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

First you'll want to copy .janitor.example.yml to .janitor.yml. You can then go in and edit exactly which tables and columns you want sanitized/ignored/cleared.

If not using the .phar, install dependencies with composer install.

Dumping

This will prompt you for the database password, then produce a gzip'd .sql file in the output/ directory.

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

Trimming

Trimming allows much smaller database dumps by reducing the data exported through the use of keeping data, scrubbing tables, and so on.

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

database-janitor's People

Contributors

gmemstr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.