Skip to main content

Consistent partial database dump utility

Project description

XDump

Build Status Coverage Status Documentation 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.

Installation

XDump can be obtained with pip:

$ pip install xdump

Usage example

Making a dump (on production replica for example):

>>> 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': 'SELECT * FROM employees ORDER BY id DESC LIMIT 2'}
)

Load a dump on you local machine:

>>> 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

  • SQLite

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 Python 3.4, 3.5 & 3.6.

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.3.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

xdump-0.3.1-py2.py3-none-any.whl (12.2 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for xdump-0.3.1.tar.gz
Algorithm Hash digest
SHA256 9f053d8315068e2bcac6e8d4fe3d27f89d3e993f10adf054803eadd1f0156c5f
MD5 6e0d4113b18c4059806520d593154c3f
BLAKE2b-256 310d0f9b5f26ff9dc642fccc246bed90a405f382713f541536c4cff8b784db37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xdump-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 94056969635ffa875ac0e069f5a69eaa6a1690dd43c27286a51f57e7d8bf48fe
MD5 bc8391e2e871d59e28c88c5703874598
BLAKE2b-256 55bf01fbccbc6d550cbda28b785376af8b07f6845ab1fb6f944aa04f0c2e7a94

See more details on using hashes here.

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