Skip to main content

Consistent partial database dump utility

Project description

XDump

Build Status Coverage Status Latest PyPI version

XDump is an utility to make partial consistent dump and load it into the database.

The idea is to provide an ability to specify what to include in the dump via SQL queries. Responsibility for dump integrity lays on the user in this case.

Installation

XDump can be obtained with pip:

$ pip install xdump

Usage example

Making a dump (on production replica for example):

>>> EMPLOYEES_SQL = '''
WITH RECURSIVE employees_cte AS (
  SELECT *
  FROM recent_employees
  UNION
  SELECT E.*
  FROM employees E
  INNER JOIN employees_cte ON (employees_cte.manager_id = E.id)
), recent_employees AS (
  SELECT *
  FROM employees
  ORDER BY id DESC
  LIMIT 2
)
SELECT * FROM employees_cte
'''
>>> from xdump.postgresql import PostgreSQLBackend
>>> backend = PostgreSQLBackend(dbname='app_db', user='prod', password='pass', host='127.0.0.1', port='5432')
>>> backend.dump('/path/to/dump.zip', full_tables=['groups'], partial_tables={'employees': EMPLOYEES_SQL})

Load a dump on you local machine:

from xdump.postgresql import PostgreSQLBackend
>>> backend = PostgreSQLBackend(dbname='app_db', user='local', password='pass', host='127.0.0.1', port='5432')
>>> backend.load('/path/to/dump.zip')

RDBMS support

At the moment only the following are supported:

  • PostgreSQL

Django support

Add xdump.extra.django to your INSTALLED_APPS settings:

INSTALLED_APPS = [
   ...,
   'xdump.extra.django',
]

Add XDUMP to your project settings file. It should contain minimum 2 entries:

  • FULL_TABLES - a list of tables, that should be fully dumped.

  • PARTIAL_TABLES - a dictionary with table_name: select SQL

XDUMP = {
    'FULL_TABLES': ['groups'],
    'PARTIAL_TABLES': {'employees': 'SELECT * FROM employees WHERE id > 100'}
}

Optionally you could use a custom backend:

XDUMP = {
    ...,
    'BACKEND': 'importable.string',
}

Run xdump command:

$ ./manage.py xdump dump.zip

Run xload command:

$ ./manage.py xload dump.zip

Possible options to both commands:

  • alias - allows you to choose database config from DATABASES, that is used during the execution;

  • backend - importable string, that leads to custom dump backend class.

The following make command could be useful to get a configured dump from production to your local machine:

sync-production:
    ssh -t $(TARGET) "DJANGO_SETTINGS_MODULE=settings.production /path/to/manage.py xdump /tmp/dump.zip"
    scp $(TARGET):/tmp/dump.zip ./dump.zip
    ssh -t $(TARGET) "rm /tmp/dump.zip"
    DJANGO_SETTINGS_MODULE=settings.local $(PYTHON) manage.py xload ./dump.zip

And usage is:

$ make sync-production TARGET=john@production.com PYTHON=/path/to/python/in/venv

Python support

XDump supports only Python 3.6 at the moment (but the supported versions list will be extended in the future).

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

xdump-0.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

xdump-0.1-py2.py3-none-any.whl (12.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file xdump-0.1.tar.gz.

File metadata

  • Download URL: xdump-0.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for xdump-0.1.tar.gz
Algorithm Hash digest
SHA256 b44c588fb9d997402ddf46ed7744035e3826008dd6514590d8d8a751c480fb4e
MD5 1d70a870337652b696fc29572b3ffa3e
BLAKE2b-256 d451db930feaf9c20aa0312aa752e01fae94dbd613ddc13d6591a54fc8e4fba7

See more details on using hashes here.

File details

Details for the file xdump-0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for xdump-0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 54424ed1d273d53997d659b382921ba24f28d14594bf7f60323c585fc097e2cc
MD5 2e6943f3a4d26e4ab76855183600307a
BLAKE2b-256 3f8f80e58728f93e9c2028b44162d948d939397b64b52b001f2f694a35b575f0

See more details on using hashes here.

Supported by

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