简体   繁体   中英

dbbackup specify which pg_dump to use

When calling

from django.core.management import call_command
call_command('dbbackup', compress=True, interactive=False)

I get:

CommandConnectorError: Error running:  pg_dump xxx --host=localhost --port=xxx --username=xxx --no-password --clean 
pg_dump: server version: 9.6.5; pg_dump version: 8.4.20
pg_dump: aborting because of server version mismatch

I'm using a non-root installation of PostgreSQL (version 9.6.5 ) as backend for a django application. (Used this tutorial for the installation.)

There is also a postgreSQL installation in the machine (version 8.4.20 ).

Before I switched to the non-root installation, everything worked flawlessly. My guess is that the pg_dump called in dbbackup is still the one from the root installation.

How can one specify which pg_dump to use?

If you have made a non-root installation of postgreSQL, say with the user nonrootuser , then you should find psql as well as pg_dump for this installation under /home/nonrootuser/postgres/bin/ . This is the pg_dump you want to use.

Dbbackup allows you to specify the connector it uses to create the backup. In particular it allows you to specify the dump command ( DUMP_CMD ). To specify the connector, add the following block to your settings.py:

import os  # if not yet imported
DBBACKUP_CONNECTORS = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'xxx',
        'USER': 'xxx',
        'PASSWORD': 'xxx',
        'HOST': 'xxx',
        'PORT': 'xxx',
        'DUMP_CMD': os.path.join(
            os.environ["HOME"],
            'nonrootuser',
            'bin',
            'pg_dump'
            )
        }
    }

Replace the xxx with your specific values.

Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM