Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'invoke restore' relation does not exist #8918

Open
2 of 6 tasks
ursincantieni opened this issue Jan 20, 2025 · 10 comments
Open
2 of 6 tasks

'invoke restore' relation does not exist #8918

ursincantieni opened this issue Jan 20, 2025 · 10 comments
Labels
bug Identifies a bug which needs to be addressed plugin Plugin ecosystem setup Relates to the InvenTree setup / installation process

Comments

@ursincantieni
Copy link

Please verify that this bug has NOT been raised before.

  • I checked and didn't find a similar issue

Describe the bug*

Similar issue #8605, but it's solution doesn't fully solve my problem.

I need to properly backup all data and be able to restore it on a new system. This should not just include parts etc, but also plugins, api keys, etc.

With invoke import-records I can successfully restore part data etc, but I lose users and so on. Invoke restore doesn't crashes with

Steps to Reproduce

Create backup from 'old' system

Before backup, run

sudo docker compose run --rm inventree-server invoke update

Create backup with

sudo docker compose run --rm inventree-server invoke backup

and export records with

sudo docker compose run --rm inventree-server invoke export-records -f "data/data.json"

Setup new system

Copy .env, Caddyfile and docker-compose.yml from old system to new one.
Initialize database with

sudo docker compose run --rm inventree-server invoke update --skip-backup

and copy data backup default-Z.psql.bin.gz to inventree-data/backup.
Running

sudo docker compose run --rm inventree-server invoke restore -d default-<NUMBERS>.psql.bin.gz

fails with the logs attached.

If instead of running invoke update, I run

sudo docker compose run --rm inventree-server invoke import-records -c -f 'data/data.json'

it successfully completes and restores all the parts, but is missing plugins, API keys, etc.

Any ideas what's going wrong? Any more generally, is this the recommended approach to backing up data? Would simply archiving the inventree-data directory make sense?

Expected behaviour

Successfully restore all data, including parts, api keys, plugins, aso

Deployment Method

  • Docker
  • Package
  • Bare metal
  • Other - added info in Steps to Reproduce

Version Information

0.17.0

Please verify if you can reproduce this bug on the demo site.

  • I can reproduce this bug on the demo site.

Relevant log output

### Logs of `invoke restore`

[+] Creating 2/0
 ✔ Container inventree-cache  Running                                                                                 0.0s 
 ✔ Container inventree-db     Running                                                                                 0.0s 
Loading config file : /home/inventree/data/config.yaml
Restoring InvenTree database
Python version 3.11.9 - /usr/local/bin/python3
/root/.local/lib/python3.11/site-packages/allauth/exceptions.py:9: UserWarning: allauth.exceptions is deprecated, use allauth.core.exceptions
  warnings.warn("allauth.exceptions is deprecated, use allauth.core.exceptions")
2025-01-20 08:17:15,105 INFO Restoring backup for database 'default' and server 'None'
2025-01-20 08:17:15,106 INFO Restoring: default-8ebe3e3ea933-2025-01-20-074704.psql.bin.gz
2025-01-20 08:17:15,109 INFO Restore tempfile created: 473.4 KiB
2025-01-20 08:17:15,110 DEBUG  pg_restore --dbname=postgresql://user:user@inventree-db:5432/inventree --single-transaction --clean 
Traceback (most recent call last):
  File "/home/inventree/src/backend/InvenTree/manage.py", line 24, in <module>
    main()
  File "/home/inventree/src/backend/InvenTree/manage.py", line 20, in main
    execute_from_command_line(sys.argv)
  File "/root/.local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/root/.local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/root/.local/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/root/.local/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/dbbackup/management/commands/dbrestore.py", line 87, in handle
    self._restore_backup()
  File "/root/.local/lib/python3.11/site-packages/dbbackup/management/commands/dbrestore.py", line 143, in _restore_backup
    self.connector.restore_dump(input_file)
  File "/root/.local/lib/python3.11/site-packages/dbbackup/db/base.py", line 106, in restore_dump
    return self._restore_dump(dump)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/dbbackup/db/postgresql.py", line 145, in _restore_dump
    stdout, stderr = self.run_command(cmd, stdin=dump, env=self.restore_env)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/dbbackup/db/base.py", line 172, in run_command
    raise exceptions.CommandConnectorError(
dbbackup.db.exceptions.CommandConnectorError: Error running:  pg_restore --dbname=postgresql://user:user@inventree-db:5432/inventree --single-transaction --clean 
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 4205; 2606 42786 FK CONSTRAINT inventree_kicad_selectedcategory inventree_kicad_sele_footprint_parameter__747c08c6_fk_part_part user
pg_restore: error: could not execute query: ERROR:  relation "public.inventree_kicad_selectedcategory" does not exist
Command was: ALTER TABLE ONLY public.inventree_kicad_selectedcategory DROP CONSTRAINT inventree_kicad_sele_footprint_parameter__747c08c6_fk_part_part;

ERROR: InvenTree command failed: 'python3 manage.py dbrestore --noinput --uncompress -v 2 -i default-8ebe3e3ea933-2025-01-20-074704.psql.bin.gz'
- Refer to the error messages in the log above for more information
@ursincantieni ursincantieni added bug Identifies a bug which needs to be addressed question This is a question triage:not-checked Item was not checked by the core team labels Jan 20, 2025
@SchrodingersGat
Copy link
Member

SchrodingersGat commented Jan 20, 2025

Ah ok, that is an interesting failure mode.

So, you have plugin(s) installed which make changes to the database - in this case the inventree-kicad plugin (thanks @afkiwers ;) )

When you create the new database schema (via invoke update) the core database tables are constructed - but not the tables associated with the plugins.

What if you try the following sequence (where O = Old database, N = new database)...

  1. O: invoke update
  2. O: invoke backup
  3. N: invoke install
  4. N: invoke restore -d <backup>

Here, you are explicitly skipping the update step for the new database. Looking at the django-dbbackup documentation what you may want to do is import the records and scheme, not just the records...

@matmair matmair added plugin Plugin ecosystem setup Relates to the InvenTree setup / installation process and removed question This is a question triage:not-checked Item was not checked by the core team labels Jan 20, 2025
@matmair
Copy link
Member

matmair commented Jan 20, 2025

@SchrodingersGat we probably are missing the required settings to activate the plugins so that the schema is missing. To address this we probably would need a small file that contains info regarding versions and plugins source to ensure the environments match. That would also help with general backup / restore tasks as it would enable better error messages.
Could be a bunch of work though

@ursincantieni
Copy link
Author

@SchrodingersGat Thanks for the fast response. I tried your steps and unfortunately run into similar issues, see 1st log.

Another thing I tried now:

  1. O: invoke update
  2. O: invoke backup
  3. N: invoke backup
  4. Start docker containers, install kicad plugins, stop containers
  5. N: invoke migrate
  6. N: invoke restore -d <backup>

This creates a similar outcome as the initial attempt, see 2nd log.

1st log

ubuntu@hardware-schmerz:~/test$ sudo docker compose run --rm inventree-server invoke restore -d default-99ca1bed8f9e-2025-01-30-100412.psql.bin.gz
[+] Creating 2/2
 ✔ Container inventree-cache  Running                                                                                  0.0s 
 ✔ Container inventree-db     Recreated                                                                                0.3s 
[+] Running 1/1
 ✔ Container inventree-db  Started                                                                                     0.3s 
Loading config file : /home/inventree/data/config.yaml
Restoring InvenTree database
Python version 3.11.9 - /usr/local/bin/python3
/root/.local/lib/python3.11/site-packages/allauth/exceptions.py:9: UserWarning: allauth.exceptions is deprecated, use allauth.core.exceptions
  warnings.warn("allauth.exceptions is deprecated, use allauth.core.exceptions")
Failed to set maintenance mode state
2025-01-30 10:07:31,853 WARNING Failed to set maintenance mode state
Failed to reset pricing flags - database not ready
Traceback (most recent call last):
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
psycopg.errors.UndefinedTable: relation "part_partpricing" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "part_partpricing" WHERE "...
                                          ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/inventree/src/backend/InvenTree/part/apps.py", line 68, in reset_part_pricing_flags
    if items.count() > 0:
       ^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/query.py", line 608, in count
    return self.query.get_count(using=self.db)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/query.py", line 568, in get_count
    return obj.get_aggregation(using, {"__count": Count("*")})["__count"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/query.py", line 554, in get_aggregation
    result = compiler.execute_sql(SINGLE)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
    cursor.execute(sql, params)
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/root/.local/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
django.db.utils.ProgrammingError: relation "part_partpricing" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "part_partpricing" WHERE "...
                                          ^
2025-01-30 10:07:31,857 ERROR Failed to reset pricing flags - database not ready
Traceback (most recent call last):
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
psycopg.errors.UndefinedTable: relation "part_partpricing" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "part_partpricing" WHERE "...
                                          ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/inventree/src/backend/InvenTree/part/apps.py", line 68, in reset_part_pricing_flags
    if items.count() > 0:
       ^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/query.py", line 608, in count
    return self.query.get_count(using=self.db)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/query.py", line 568, in get_count
    return obj.get_aggregation(using, {"__count": Count("*")})["__count"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/query.py", line 554, in get_aggregation
    result = compiler.execute_sql(SINGLE)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
    cursor.execute(sql, params)
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/root/.local/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
django.db.utils.ProgrammingError: relation "part_partpricing" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "part_partpricing" WHERE "...
                                          ^
Database not ready for creating default report templates
2025-01-30 10:07:31,864 WARNING Database not ready for creating default report templates
Failed to set maintenance mode state
2025-01-30 10:07:31,870 WARNING Failed to set maintenance mode state
Database was not ready for initializing machines
2025-01-30 10:07:31,873 WARNING Database was not ready for initializing machines
Failed to remove obsolete tasks - database not ready
Traceback (most recent call last):
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
psycopg.errors.UndefinedTable: relation "django_q_schedule" does not exist
LINE 1: SELECT 1 AS "a" FROM "django_q_schedule" WHERE "django_q_sch...
                             ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/inventree/src/backend/InvenTree/InvenTree/apps.py", line 102, in remove_obsolete_tasks
    if obsolete_tasks.exists():
       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/query.py", line 1241, in exists
    return self.query.has_results(using=self.db)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/query.py", line 598, in has_results
    return compiler.has_results()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1530, in has_results
    return bool(self.execute_sql(SINGLE))
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
    cursor.execute(sql, params)
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/root/.local/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
django.db.utils.ProgrammingError: relation "django_q_schedule" does not exist
LINE 1: SELECT 1 AS "a" FROM "django_q_schedule" WHERE "django_q_sch...
                             ^
2025-01-30 10:07:31,874 ERROR Failed to remove obsolete tasks - database not ready
Traceback (most recent call last):
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
psycopg.errors.UndefinedTable: relation "django_q_schedule" does not exist
LINE 1: SELECT 1 AS "a" FROM "django_q_schedule" WHERE "django_q_sch...
                             ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/inventree/src/backend/InvenTree/InvenTree/apps.py", line 102, in remove_obsolete_tasks
    if obsolete_tasks.exists():
       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/query.py", line 1241, in exists
    return self.query.has_results(using=self.db)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/query.py", line 598, in has_results
    return compiler.has_results()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1530, in has_results
    return bool(self.execute_sql(SINGLE))
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
    cursor.execute(sql, params)
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/root/.local/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
django.db.utils.ProgrammingError: relation "django_q_schedule" does not exist
LINE 1: SELECT 1 AS "a" FROM "django_q_schedule" WHERE "django_q_sch...
                             ^
Traceback (most recent call last):
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
psycopg.errors.UndefinedTable: relation "django_q_schedule" does not exist
LINE 1: ...", "django_q_schedule"."intended_date_kwarg" FROM "django_q_...
                                                             ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/inventree/src/backend/InvenTree/manage.py", line 24, in <module>
    main()
  File "/home/inventree/src/backend/InvenTree/manage.py", line 20, in main
    execute_from_command_line(sys.argv)
  File "/root/.local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/root/.local/lib/python3.11/site-packages/django/core/management/__init__.py", line 416, in execute
    django.setup()
  File "/root/.local/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/root/.local/lib/python3.11/site-packages/django/apps/registry.py", line 124, in populate
    app_config.ready()
  File "/home/inventree/src/backend/InvenTree/InvenTree/apps.py", line 61, in ready
    self.start_background_tasks()
  File "/home/inventree/src/backend/InvenTree/InvenTree/apps.py", line 120, in start_background_tasks
    for existing_task in Schedule.objects.all():
  File "/root/.local/lib/python3.11/site-packages/django/db/models/query.py", line 398, in __iter__
    self._fetch_all()
  File "/root/.local/lib/python3.11/site-packages/django/db/models/query.py", line 1881, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/query.py", line 91, in __iter__
    results = compiler.execute_sql(
              ^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
    cursor.execute(sql, params)
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/root/.local/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/root/.local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
django.db.utils.ProgrammingError: relation "django_q_schedule" does not exist
LINE 1: ...", "django_q_schedule"."intended_date_kwarg" FROM "django_q_...
                                                             ^
ERROR: InvenTree command failed: 'python3 manage.py dbrestore --noinput --uncompress -v 2 -i default-99ca1bed8f9e-2025-01-30-100412.psql.bin.gz'
- Refer to the error messages in the log above for more information

2nd log

ubuntu@hardware-schmerz:~/test$ sudo docker compose run --rm inventree-server invoke restore -d default-99ca1bed8f9e-2025-01-30-100412.psql.bin.gz
[+] Creating 2/0
 ✔ Container inventree-db     Running                                                                                  0.0s 
 ✔ Container inventree-cache  Running                                                                                  0.0s 
Loading config file : /home/inventree/data/config.yaml
Restoring InvenTree database
Python version 3.11.9 - /usr/local/bin/python3
/root/.local/lib/python3.11/site-packages/allauth/exceptions.py:9: UserWarning: allauth.exceptions is deprecated, use allauth.core.exceptions
  warnings.warn("allauth.exceptions is deprecated, use allauth.core.exceptions")
2025-01-30 10:40:20,450 INFO Restoring backup for database 'default' and server 'None'
2025-01-30 10:40:20,450 INFO Restoring: default-99ca1bed8f9e-2025-01-30-100412.psql.bin.gz
2025-01-30 10:40:20,453 INFO Restore tempfile created: 459.8 KiB
2025-01-30 10:40:20,454 DEBUG  pg_restore --dbname=postgresql://user:user@inventree-db:5432/inventree --single-transaction --clean 
Traceback (most recent call last):
  File "/home/inventree/src/backend/InvenTree/manage.py", line 24, in <module>
    main()
  File "/home/inventree/src/backend/InvenTree/manage.py", line 20, in main
    execute_from_command_line(sys.argv)
  File "/root/.local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/root/.local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/root/.local/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/root/.local/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/dbbackup/management/commands/dbrestore.py", line 87, in handle
    self._restore_backup()
  File "/root/.local/lib/python3.11/site-packages/dbbackup/management/commands/dbrestore.py", line 143, in _restore_backup
    self.connector.restore_dump(input_file)
  File "/root/.local/lib/python3.11/site-packages/dbbackup/db/base.py", line 106, in restore_dump
    return self._restore_dump(dump)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/dbbackup/db/postgresql.py", line 145, in _restore_dump
    stdout, stderr = self.run_command(cmd, stdin=dump, env=self.restore_env)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/dbbackup/db/base.py", line 172, in run_command
    raise exceptions.CommandConnectorError(
dbbackup.db.exceptions.CommandConnectorError: Error running:  pg_restore --dbname=postgresql://user:user@inventree-db:5432/inventree --single-transaction --clean 
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 4205; 2606 42786 FK CONSTRAINT inventree_kicad_selectedcategory inventree_kicad_sele_footprint_parameter__747c08c6_fk_part_part user
pg_restore: error: could not execute query: ERROR:  relation "public.inventree_kicad_selectedcategory" does not exist
Command was: ALTER TABLE ONLY public.inventree_kicad_selectedcategory DROP CONSTRAINT inventree_kicad_sele_footprint_parameter__747c08c6_fk_part_part;

ERROR: InvenTree command failed: 'python3 manage.py dbrestore --noinput --uncompress -v 2 -i default-99ca1bed8f9e-2025-01-30-100412.psql.bin.gz'
- Refer to the error messages in the log above for more information

@ursincantieni
Copy link
Author

Are there any risks with simply creating backups of the entire inventree-data directory? That would be a relatively straight forward approach.

@ursincantieni
Copy link
Author

@SchrodingersGat any other ideas?:)

@SchrodingersGat
Copy link
Member

@ursincantieni you can try that for sure. Another approach would be to use the data migration guide - but nothing stopping you from trying both

@ursincantieni
Copy link
Author

@SchrodingersGat Hola, I've tried these two things:

  • Using the migration guide I can restore parts etc. but lose plugins, API keys etc - basically what I described as the problem in the initial post
  • If I copy the entire inventree-data directory to another system, run invoke update and then `invoke import-records -c -f 'data/data.json' with the exported records from the old system, I run into the same problem.

@SchrodingersGat
Copy link
Member

If you copy the data directory you don't need to run import-records - that is for the .json format only

@ursincantieni
Copy link
Author

Understood.

The issue I'm facing with all these approaches is

  1. Data from the inventree_kicad plugin in the database (there's three tables created by the plugin) are not restored by import-records. A workaround is to manually export and import those tables e.g. using DBeaver, but not ideal. To include the import of these tables in import-records, would I need to look at inventree itself or the plugin used?
  2. API keys are not restored. I couldn't find where these are stored, is this expected?

@matmair
Copy link
Member

matmair commented Feb 4, 2025

As pointed out in #8918 (comment) no information regarding plugins is in the backups

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identifies a bug which needs to be addressed plugin Plugin ecosystem setup Relates to the InvenTree setup / installation process
Projects
None yet
Development

No branches or pull requests

3 participants