diff --git a/auto_backup/README.rst b/auto_backup/README.rst
index b895cb4bae4..8176e0cd911 100644
--- a/auto_backup/README.rst
+++ b/auto_backup/README.rst
@@ -107,7 +107,6 @@ Known issues / Roadmap
you need to run the backup from outside of the main Odoo instance. How to do
this is outlined in `this blog post
`_.
-* Backups won't work if list_db=False is configured in the instance.
Bug Tracker
===========
@@ -141,6 +140,7 @@ Contributors
* Andrea Stirpe
* Aitor Bouzas
* Simone Vanin
+* klodr
* Vu Nguyen Anh
Maintainers
diff --git a/auto_backup/__manifest__.py b/auto_backup/__manifest__.py
index 1ca292e8d80..8f57a34ec72 100644
--- a/auto_backup/__manifest__.py
+++ b/auto_backup/__manifest__.py
@@ -6,7 +6,7 @@
{
"name": "Database Auto-Backup",
"summary": "Backups database",
- "version": "15.0.1.0.1",
+ "version": "15.0.1.0.2",
"author": "Yenthe Van Ginneken, "
"Agile Business Group, "
"Grupo ESOC Ingenieria de Servicios, "
diff --git a/auto_backup/models/db_backup.py b/auto_backup/models/db_backup.py
index b8625ceb323..374061aaac4 100644
--- a/auto_backup/models/db_backup.py
+++ b/auto_backup/models/db_backup.py
@@ -165,9 +165,12 @@ def action_backup(self):
shutil.copyfileobj(cached, destiny)
# Generate new backup
else:
- db.dump_db(
- self.env.cr.dbname, destiny, backup_format=rec.backup_format
- )
+ with self._db_management_enabled():
+ db.dump_db(
+ self.env.cr.dbname,
+ destiny,
+ backup_format=rec.backup_format,
+ )
backup = backup or destiny.name
successful |= rec
@@ -178,9 +181,10 @@ def action_backup(self):
filename = self.filename(datetime.now(), ext=rec.backup_format)
with rec.backup_log():
- cached = db.dump_db(
- self.env.cr.dbname, None, backup_format=rec.backup_format
- )
+ with self._db_management_enabled():
+ cached = db.dump_db(
+ self.env.cr.dbname, None, backup_format=rec.backup_format
+ )
with cached:
with rec.sftp_connection() as remote:
@@ -207,6 +211,25 @@ def action_backup_all(self):
"""Run all scheduled backups."""
return self.search([]).action_backup()
+ @contextmanager
+ def _db_management_enabled(self):
+ """Temporarily allow database management functions during a backup.
+
+ ``odoo.service.db.dump_db`` is protected by
+ ``check_db_management_enabled``, which raises ``AccessDenied`` when
+ ``list_db = False`` is set in the Odoo configuration. That option only
+ aims at hiding database management from the web interface; a scheduled
+ backup is a trusted server-side operation, so we re-enable the flag for
+ the duration of the dump and always restore its original value
+ afterwards.
+ """
+ list_db = tools.config["list_db"]
+ tools.config["list_db"] = True
+ try:
+ yield
+ finally:
+ tools.config["list_db"] = list_db
+
@contextmanager
def backup_log(self):
"""Log a backup result."""
diff --git a/auto_backup/readme/CONTRIBUTORS.rst b/auto_backup/readme/CONTRIBUTORS.rst
index e7cdbc74afa..ef7c325756f 100644
--- a/auto_backup/readme/CONTRIBUTORS.rst
+++ b/auto_backup/readme/CONTRIBUTORS.rst
@@ -5,4 +5,5 @@
* Andrea Stirpe
* Aitor Bouzas
* Simone Vanin
+* klodr
* Vu Nguyen Anh
diff --git a/auto_backup/readme/ROADMAP.rst b/auto_backup/readme/ROADMAP.rst
index e96ef407e25..555775cbe9c 100644
--- a/auto_backup/readme/ROADMAP.rst
+++ b/auto_backup/readme/ROADMAP.rst
@@ -3,4 +3,3 @@
you need to run the backup from outside of the main Odoo instance. How to do
this is outlined in `this blog post
`_.
-* Backups won't work if list_db=False is configured in the instance.
diff --git a/auto_backup/static/description/index.html b/auto_backup/static/description/index.html
index 11f0dc9fa59..f0d42383c11 100644
--- a/auto_backup/static/description/index.html
+++ b/auto_backup/static/description/index.html
@@ -464,7 +464,6 @@
settings. In order to circumvent this without frivolously changing settings,
you need to run the backup from outside of the main Odoo instance. How to do
this is outlined in this blog post.
-Backups won’t work if list_db=False is configured in the instance.
diff --git a/auto_backup/tests/test_db_backup.py b/auto_backup/tests/test_db_backup.py
index 5c77e725729..4a340324b76 100644
--- a/auto_backup/tests/test_db_backup.py
+++ b/auto_backup/tests/test_db_backup.py
@@ -127,6 +127,15 @@ def test_action_backup_local(self):
generated_backup = [f for f in os.listdir(rec_id.folder) if f >= filename]
self.assertEqual(1, len(generated_backup))
+ def test_action_backup_local_list_db_disabled(self):
+ """It should backup locally even when list_db is disabled"""
+ rec_id = self.new_record("local")
+ filename = rec_id.filename(datetime.now())
+ 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))
+
def test_action_backup_local_cleanup(self):
"""Backup local database and cleanup old databases"""
rec_id = self.new_record("local")