django-dbbackup
django-dbbackup copied to clipboard
Make more pg_dump/pg_restore flags available for migrations across databases
Feature Request
Make more pg_dump/pg_restore flags available to facilitate operations across databases.
Problem definition
When running dbbackup on one server and dbrestore on another server, especially when a separate database (i.e. migration) is used as well doesn't work. The default pg_dump/pg_restore settings include many operations that are database specific options and not relevant to django, for instance:
- The table owner will likely be different
- The
--no-ownerflag solves this problem
- The
- The database can have ACLs, roles, grants which are not related to django but to the operations of that database
- The
--no-privilegesflag solves this problem
- The
Without these flags the errors can be cryptic and hard to understand when a command on a random table or fails.
Temporary solution
I was able to solve the first 2 points above using the suggestion from https://github.com/django-dbbackup/django-dbbackup/issues/213#issuecomment-629694161
Using the following in settings.py:
DBBACKUP_CONNECTOR_MAPPING = {
'django.db.backends.postgresql': 'dbbackup.db.postgresql.PgDumpBinaryConnector',
}
DBBACKUP_CONNECTORS = {
'default': {
# 'dump_suffix': '--no-owner', # Does not work because it comes after command
'dump_cmd': 'pg_dump --no-owner --no-privileges',
'restore_cmd': 'pg_restore --no-owner --no-privileges',
}
}
Allowed me to export and import with out running into owner or ACL issues.
Possible improvements
One improvements would be to make these flags available or a way to insert arguments into the dump and restore commands (as mentioned in the issue link the suffix happens too late) would make it cleaner and improve the documentation.
Another improvement might be to consider the no owner and perhaps also the no privileges as default options, it's not ideal because it might be a breaking changes in some cases but from my understanding they're not critical or needed for a standard django installation so they might be safer defaults (especially if there's a documented way to turn them off).