Repository navigation
Conversation
odoo.service.db.dump_db is guarded by check_db_management_enabled, which raises AccessDenied ("Database management functions blocked, admin disabled database listing") when list_db = False is set in the Odoo configuration. Scheduled backups then failed silently, leaving zero-byte files.
list_db only hides database management from the web interface; a scheduled backup is a trusted server-side operation. Re-enable the flag for the duration of the dump through a context manager that always restores its original value, even on error.
Signed-off-by: klodr <[email protected]>
rrebollo
left a comment
There was a problem hiding this comment.
Ran a shell scenario on 17.0 with list_db off: the dump succeeds and the flag is restored. I would not get there by switching off a security setting; which deployments pay for that is what I could not settle.
| list_db = tools.config["list_db"] | ||
| tools.config["list_db"] = True | ||
| try: | ||
| yield |
There was a problem hiding this comment.
Switching this setting off is what I would not do: --no-database-list closes /web/database/list, auth='none' (addons/web/controllers/database.py:173), so on a threaded deployment the list answers anonymous callers while pg_dump runs (workers>0 forks the cron: nothing leaks there). Core flips it in odoo db dump (odoo/cli/db.py:124) where no server runs, and the dump is callable without it (dump_db.__wrapped__ on 17.0). Which way you take, a clear refusal included, is yours.
There was a problem hiding this comment.
Agreed: switching list_db on, even for the dump only, reopens the database manager to every request the process serves meanwhile. I measured it on 17.0 with --workers 0 --no-database-list, polling /web/database/list without a session every 20 ms during a 315 MB zip backup: 139 of 303 polls got the database list with the previous commit, 0 of 322 with the new one (and 0 with --workers 2, as you said).
dump_db.__wrapped__ alone is not enough for zip backups: dump_db calls dump_db_manifest, which is guarded too. So _dump_db now builds the dump with the same core tools and layout as dump_db (pg_dump, the filestore, osutil.zip_dir), taking the manifest from dump_db_manifest.__wrapped__; list_db is never touched. The resulting zip restores with odoo db load (same installed modules, same filestore).
| db.dump_db( | ||
| self.env.cr.dbname, destiny, backup_format=rec.backup_format | ||
| ) | ||
| with self._db_management_enabled(): |
There was a problem hiding this comment.
Reproduced: the destination is opened "wb" before the dump (db_backup.py:159), so a failed pg_dump, a full disk or a missing tool leaves a 0-byte 2026_11_23_14_06_56.dump.zip that cleanup() keeps and nothing flags. The sftp branch already dumps into a temporary file and only writes the destination afterwards; the local path leaving the same artefact on a failed dump is the part I would fix here.
There was a problem hiding this comment.
Fixed: local backups are written to a partial file of their own (<name>.<uuid>.part), renamed only once complete and removed on failure, so cleanup() never sees an empty or truncated backup. pg_dump also runs with check=True in both formats; the core dump format path did not check its exit status.
| with patch.dict(tools.config.options, {"list_db": False}): | ||
| rec_id.action_backup() | ||
| generated_backup = [f for f in os.listdir(rec_id.folder) if f >= filename] | ||
| self.assertEqual(1, len(generated_backup)) |
There was a problem hiding this comment.
Reverted the fix and ran this scenario: dump_db raises AccessDenied, backup_log() logs it and returns, and the zero-byte file opened at db_backup.py:159 is still in the folder, so generated_backup holds one entry and this assertion passes without the change. Asserting the dump has content makes it a regression test:
| self.assertEqual(1, len(generated_backup)) | |
| self.assertEqual(1, len(generated_backup)) | |
| backup_path = os.path.join(rec_id.folder, generated_backup[0]) | |
| self.assertGreater(os.path.getsize(backup_path), 0) |
There was a problem hiding this comment.
Thanks, the tests now assert that pg_dump runs with list_db still off, that zip (dump.sql, manifest.json) and dump (PGDMP header) backups have content, and that a failed dump leaves no file behind and posts the failure. They fail against the previous commit (list_db seen on, 0-byte file left) and against the unfixed module.
| "name": "Database Auto-Backup", | ||
| "summary": "Backups database", | ||
| "version": "17.0.1.1.1", | ||
| "version": "17.0.1.1.2", |
There was a problem hiding this comment.
The version bump comes from ocabot on merge ([BOT] post-merge updates is what last touched this line), so a [FIX] leaves it alone and the diff stays with the fix itself:
| "version": "17.0.1.1.2", | |
| "version": "17.0.1.1.1", |
Switching list_db on for the duration of the dump reopened the database manager routes, /web/database/list included (auth='none'), to every request served meanwhile by the same process: on a threaded server, anonymous callers got the database list for the whole backup. Build the dump in the module instead, with the same core tools and the same layout as odoo.service.db.dump_db (pg_dump, the filestore, osutil.zip_dir), taking the manifest from the undecorated dump_db_manifest. list_db is never touched. Calling dump_db.__wrapped__ alone is not enough for zip backups: it calls dump_db_manifest, which is guarded too. pg_dump now runs with check=True in both formats, and local backups are written to a partial file of their own, renamed only once complete: a failed dump no longer leaves an empty or truncated file that cleanup() keeps. The tests assert that list_db stays off while pg_dump runs, that zip and dump backups have content, and that a failed dump leaves no file behind; they fail without this change. The version bump is left to ocabot. Signed-off-by: klodr <[email protected]>
|
On the same module: #3683 is |
| reopen the database manager routes, ``/web/database/list`` included, | ||
| to every request served meanwhile by the same process. The dump is | ||
| therefore built here with the same core tools and the same layout as | ||
| ``dump_db``, taking the manifest from the undecorated |
There was a problem hiding this comment.
This now owns a copy of core's dump layout. Naming odoo/service/db.py::dump_db (17.0) as what it mirrors is enough for the next reader to diff it when core changes the zip or the manifest; today the two are identical, manifest included.
| else: | ||
| self._dump_db(destiny, rec.backup_format) | ||
| os.replace(partial, destination) | ||
| finally: |
There was a problem hiding this comment.
The finally only runs in-process: a hard crash or a container stop leaves <name>.dump.zip.<uuid>.part behind, and cleanup() only globs *.dump.zip, so nothing ever removes it. A sweep of stale .part files in cleanup(), or a line in the readme, would close it; read from the code, not run.
Problem
When
list_db = Falseis set in the Odoo configuration, scheduledauto_backupjobs fail with:
odoo.service.db.dump_dbis decorated with@check_db_management_enabled, whichraises
AccessDeniedwhenlist_dbis False. The backup fails and leaves azero-byte dump file that
cleanup()keeps and nothing flags.Fix
_dump_dbbuilds the dump in the module, with the same core tools and layoutas
dump_db(pg_dump, the filestore,osutil.zip_dir), taking the manifestfrom the undecorated
dump_db_manifest.list_dbis never touched: switchingit on, even for the dump only, would reopen
/web/database/listto anonymouscallers on a threaded server.
pg_dumpruns withcheck=Truein both formats.complete: a failed dump leaves no empty or truncated file behind.
Tests assert that
pg_dumpruns withlist_dbstill off, that zip and dumpbackups have content, and that a failed dump leaves no file; they fail without
the fix.
Port of #3639.