Consistent partial database dump utility
Project description
XDump
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):
>>> EMPLOYEES_SQL = 'SELECT * FROM employees ORDER BY id DESC LIMIT 2'
>>> 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})
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file xdump-0.3.0.tar.gz
.
File metadata
- Download URL: xdump-0.3.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6084f5e25f060690aaab92fdf968a960e3d05f90f1570f6fc7fab6fd9b593132 |
|
MD5 | 7667c64567c9410ee70c7ff0e32ce75b |
|
BLAKE2b-256 | b7d60fa3baf49893c0b68f6844ba1430f425f7e3b1b2941b96ef262a99b70208 |
File details
Details for the file xdump-0.3.0-py2.py3-none-any.whl
.
File metadata
- Download URL: xdump-0.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7741356056a73ab863d73e1fbc29a75c2186535b7d39e7fda2c481b5ebea02a3 |
|
MD5 | 7615a19b3e96e0fcca1e2e87f308c252 |
|
BLAKE2b-256 | 9093dd97ae9978d9ca5c9255cb8dfe12778c16eea1230c9b4eb7a7b1876c3a77 |