2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-02-25 16:17:58 +00:00

feat(backend): ensure restore of backups only works in correct enviroments (#11372)

* [FR] ensure restore of backups only works in correct enviroments
Fixes #11214

* update PR nbr

* fix wrong ty detection

* fix link

* ensure tracing does not enagage while running backup ops

* fix import

* remove debugging string

* add error codes

* add tests for backup and restore

* complete test for restore

* we do not need e2e on every matrix entry
there is no realy db dep here

* fix changelog format

* add flag to allow bypass
This commit is contained in:
Matthias Mair
2026-02-25 00:23:00 +01:00
committed by GitHub
parent 8a4ad4ff62
commit ac9a1f2251
7 changed files with 329 additions and 14 deletions

View File

@@ -793,6 +793,7 @@ def backup(
'skip_db': 'Do not import database archive (media restore only)',
'skip_media': 'Do not import media archive (database restore only)',
'uncompress': 'Uncompress the backup files before restoring (default behavior)',
'restore_allow_newer_version': 'Allow restore from a newer version backup (use with caution)',
}
)
def restore(
@@ -804,10 +805,16 @@ def restore(
skip_db: bool = False,
skip_media: bool = False,
uncompress: bool = True,
restore_allow_newer_version: bool = False,
):
"""Restore the database and media files."""
base_cmd = '--noinput -v 2'
env = {}
if restore_allow_newer_version:
env['INVENTREE_BACKUP_RESTORE_ALLOW_NEWER_VERSION'] = 'True'
if uncompress:
base_cmd += ' --uncompress'
@@ -831,7 +838,7 @@ def restore(
if db_file:
cmd += f' -i {db_file}'
manage(c, cmd)
manage(c, cmd, env=env)
if skip_media:
info('Skipping media restore...')
@@ -842,7 +849,7 @@ def restore(
if media_file:
cmd += f' -i {media_file}'
manage(c, cmd)
manage(c, cmd, env=env)
@task()