lino.management.commands.dump2py

This defines the dump2py management command.

dump2py

Write a dump of your database to a set of Python modules. This dump is useful for creating a daily backup or before an upgrade with data migration.

Usage: cd to your project directory and say:

$ python manage.py dump2py TARGET

This will create a python dump of your database to the directory TARGET.

The directory will contain a file restore.py and a series of .py files (one for every model) which are being execfile()d from that restore.py.

Options:

--noinput

Do not prompt for user input of any kind.

--tolerate

Tolerate database errors. This can help making a partial snapshot of a database which is not (fully) synced with the application code.

--overwrite

Don't complain if the TARGET directory already exists. This will potentially overwrite existing files.

--max-row-count <NUM>

Change the maximum number of rows per source file from its default value (50000) to NUM.

When a table contains many rows, the resulting .py file can become so large that it doesn't fit into memory, causing the Python process to get killed when it tries to restore the data. To avoid this limitation, dump2py distributes the content over several files if a table contains are more than NUM rows.

The default value has been "clinically tested" and should be small enough for most machines.

FILES

restore.py

The main script of a Python dump generated by the dump2py command.

To restore a dump created using dump2py to your database, simply run the restore.py script using the run management command:

$ python manage.py run mydump/restore.py

SEE ALSO

(This module's source code is available here.)

Functions

is_pointer_to_contenttype(f)

write_create_function(model, stream)

Classes

Command([stdout, stderr, no_color, force_color])