Skip to main content

Synchronize a database from and to client systems.

Project description

Database Sync Tool

Python script to synchronize a database from an origin to a target system.

Supported framework types:

Prerequisite

The script needs python 3.7 or higher. It is necessary for some additional functionalities to have pip installed on your local machine.

Installation

pip

The library can be installed from PyPI:

$ pip3 install db-sync-tool-kmi

composer

While using the script within the PHP framework context, the script is available via packagist.org using composer:

$ composer require kmi/db-sync-tool

Additionally install the python requirements via the following pip command:

$ pip3 install -r vendor/kmi/db-sync-tool/requirements.txt

Configuration

The config.json contains important information about the origin and the target system. In dependence on the given configuration the synchronisation mode is implicitly selected.

# Copy/edit host.json for TYPO3
$ cp docs/dist/t3-db-sync.json.dist config.json

# Copy/edit host.json for Symfony
$ cp docs/dist/sf-db-sync.json.dist config.json

Example structure of config.json for a Symfony system in receiver mode:

{
  "name": "project",
  "type": "Symfony",
  "target": {
    "path": "/var/www/html/app/.env"
  },
  "origin": {
    "host": "ssh_host",
    "user": "ssh_user",
    "path": "/var/www/html/project/shared/.env"
  },
  "ignore_table": []
}

Adjustments

It is possible to adjust the config.json configuration.

Sync modes

The script provides seven different kinds of synchronisation modes.

  • Receiver
  • Sender
  • Proxy
  • Dump Local
  • Dump Remote
  • Import Local
  • Import Remote

Usage

Command line

Run the python script:

$ python3 db_sync_tool/sync.py
# Options
-h, --help              Show help
-v, --verbose           Enable extended console output
-f, --file              Path to host file
-i, --importfile        Import database from a specific file dump
-dn, --dumpname         Set a specific dump file name (default is "_[dbname]_[date]")
-kd, --keepdump         Skipping target import of the database dump and saving the available dump file in the given directory
-o, --hosts             Using an additional hosts file for merging hosts information with the configuration file

If you haven't declare a path to a SSH key, during the script execution you are requested to enter the SSH password for the given user in the host.json to enable a SSH connection to the remote system.

Import

You can import the python package and use them inside your project:

import db_sync_tool

if __name__ == "__main__":
    db_sync_tool.Sync(args, config)

Build

The packaging process of the python module is described on python.org.

Tests

A docker container set up is available for testing purpose. See here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

db_sync_tool-kmi-2.1.0.tar.gz (16.4 kB view hashes)

Uploaded Source

Built Distribution

db_sync_tool_kmi-2.1.0-py3-none-any.whl (37.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page