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

Dump is compressed by default. Compression level could be changed with passing compression argument to dump method. Valid options are zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED, zipfile.ZIP_BZIP2 and zipfile.ZIP_LZMA.

Verbosity of the output could be customized via verbosity (with values 0, 1 or 2) argument of a backend class.

There are two options to control the content of the dump:

  • dump_schema - controls if the schema should be included

  • dump_data - controls if the data should be included

RDBMS support

At the moment only the following are supported:

  • PostgreSQL

  • SQLite >= 3.8.3

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.

  • dump_schema - controls if the schema should be included

  • dump_data - controls if the data should be included

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 2.7, 3.4 - 3.7 and PyPy 2 & 3.

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

Uploaded Source

Built Distribution

xdump-0.5.0-py2.py3-none-any.whl (14.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: xdump-0.5.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.5

File hashes

Hashes for xdump-0.5.0.tar.gz
Algorithm Hash digest
SHA256 cc4ae9992b41883148629c24fa23c6199e9c8a9d3744b5a4c9aae472136e1594
MD5 d634658bab371e9e15bcabb890cb6db5
BLAKE2b-256 8ab6ee6e255fb0f4efcae56f5c1e24fa66e00bea0d90457cf9a9a70b360c7d7f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xdump-0.5.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.5

File hashes

Hashes for xdump-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9ef4e4e8088656811db45bc1752af65d7571901aa428bd5c5384109020d32c8e
MD5 b8f9b56ee0831ef7939bb286e2eac162
BLAKE2b-256 cb8bb3a88a73266027769a6fbac11852d184a8928e06929ea374a423195cfa52

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