Skip to main content

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

Metadata

Release files for xdump 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xdump 0.1.2
File Size Uploaded
xdump-0.1.2.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xdump 0.1.2
File Interpreter ABI Platform
xdump-0.1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 20.9 kB

Release files / xdump-0.1.2.tar.gz

Download URL xdump-0.1.2.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6c2932a392c39896a7bb0cddc1965d3b45ff5f14d9a07a85e4fbf2fcf424c56e
BLAKE2b-256 checksum
How to use checksums
88971658a0257dac58cacd293486f05d9aa60e50e1e582015f668607d205499e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / xdump-0.1.2-py2.py3-none-any.whl

Download URL xdump-0.1.2-py2.py3-none-any.whl
Size 11.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
709398a53a18f3dd51cd1ef1efa0d54aa96a6129ec8b9f23c7c7e841cbff2d9e
BLAKE2b-256 checksum
How to use checksums
e1bd402e68563ffce8eeb8fa439a655de59000d8aff9cc3d23e589606c41ba7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page