jazzband / django-dbbackup

Management commands to help backup and restore your project database and media files
BSD 3-Clause "New" or "Revised" License
981 stars 220 forks source link

pg_restore: error: input file appears to be a text format dump. Please use psql. #482

Open roflmaostc opened 1 year ago

roflmaostc commented 1 year ago

Hi,

Since recently, the command python manage.py dbrestore -I file.psql does not work for me anymore.

You got any idea or help how to fix this?

I'm using Linux and psql (PostgreSQL) 15.2 and

django-dbbackup               4.0.2
Django                        3.2.18
Python 3.10.10
(orpheus) ╭─fxw@earth ~/Documents/Orpheus/django/orpheuscc  ‹master*› 
╰─➤  python manage.py dbrestore -I ../orpheuscc_backup/orpheuscc/default-orpheus-2023-04-22-033304.psql                                  [23-04-23 | 1:06:17]
Are you sure you want to continue? [Y/n] Y
Traceback (most recent call last):
  File "/home/fxw/Documents/Orpheus/django/orpheuscc/manage.py", line 21, in <module>
    main()
  File "/home/fxw/Documents/Orpheus/django/orpheuscc/manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/fxw/Documents/Orpheus/django/orpheus/lib/python3.10/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/fxw/Documents/Orpheus/django/orpheus/lib/python3.10/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/fxw/Documents/Orpheus/django/orpheus/lib/python3.10/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/fxw/Documents/Orpheus/django/orpheus/lib/python3.10/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/fxw/Documents/Orpheus/django/orpheus/lib/python3.10/site-packages/dbbackup/management/commands/dbrestore.py", line 68, in handle
    self._restore_backup()
  File "/home/fxw/Documents/Orpheus/django/orpheus/lib/python3.10/site-packages/dbbackup/management/commands/dbrestore.py", line 118, in _restore_backup
    self.connector.restore_dump(input_file)
  File "/home/fxw/Documents/Orpheus/django/orpheus/lib/python3.10/site-packages/dbbackup/db/base.py", line 105, in restore_dump
    return self._restore_dump(dump)
  File "/home/fxw/Documents/Orpheus/django/orpheus/lib/python3.10/site-packages/dbbackup/db/postgresql.py", line 124, in _restore_dump
    stdout, stderr = self.run_command(cmd, stdin=dump, env=self.restore_env)
  File "/home/fxw/Documents/Orpheus/django/orpheus/lib/python3.10/site-packages/dbbackup/db/base.py", line 171, in run_command
    raise exceptions.CommandConnectorError(
dbbackup.db.exceptions.CommandConnectorError: Error running:  pg_restore --dbname=postgresql://XXXXXX:XXXXX-G-6iXeiJ@localhost/XXXXXX --single-transaction --clean 
pg_restore: error: input file appears to be a text format dump. Please use psql.

CC: @maxtechcode

rodleiva commented 11 months ago

To complement. I confirm the problem. I have backup files from a system running the following: Django 3.2.9 django-dbbackup 3.3 backend database: postgres

The dump file generated by dbbackup are compressed text files *.psql.gz

The upgraded system running the following: Django==4.2.7 django-dbbackup==4.0.2

Without changes in the configuration, the dump files generated by dbbackup are now binary compressed files *.psql.bin.gz I can import the bin.gz files, but I'm unable to import the text dumps generated with the previous version.

The solution is given in #456, to set this configuration in settings.py to override the default config of dbbackup.

DBBACKUP_CONNECTOR_MAPPING = {
    "django.db.backends.postgresql": "dbbackup.db.postgresql.PgDumpConnector",
}