[MIG] auto_backup: Migration to 17.0

pull/3180/head
rpinset 2024-06-28 10:06:42 +02:00 committed by Christian-RB
parent 8b2728e20a
commit 72121cc6b4
7 changed files with 68 additions and 64 deletions

View File

@ -107,8 +107,9 @@ Known issues / Roadmap
- On larger databases, it is possible that backups will die due to Odoo - On larger databases, it is possible that backups will die due to Odoo
server settings. In order to circumvent this without frivolously server settings. In order to circumvent this without frivolously
changing settings, you need to run the backup from outside of the main changing settings, you need to run the backup from outside of the main
Odoo instance. How to do this is outlined in `this blog Odoo instance. How to do this (for version 9.0) was outlined in `this
post <https://blog.laslabs.com/2016/10/running-python-scripts-within-odoos-environment/>`__. blog
post <https://web.archive.org/web/20240805225230/https://blog.laslabs.com/2016/10/running-python-scripts-within-odoos-environment/>`__.
- Backups won't work if list_db=False is configured in the instance. - Backups won't work if list_db=False is configured in the instance.
Bug Tracker Bug Tracker

View File

@ -6,7 +6,7 @@
{ {
"name": "Database Auto-Backup", "name": "Database Auto-Backup",
"summary": "Backups database", "summary": "Backups database",
"version": "16.0.1.0.0", "version": "17.0.1.0.0",
"author": "Yenthe Van Ginneken, " "author": "Yenthe Van Ginneken, "
"Agile Business Group, " "Agile Business Group, "
"Grupo ESOC Ingenieria de Servicios, " "Grupo ESOC Ingenieria de Servicios, "

View File

@ -216,8 +216,7 @@ class DbBackup(models.Model):
_logger.exception("Database backup failed: %s", self.name) _logger.exception("Database backup failed: %s", self.name)
escaped_tb = tools.html_escape(traceback.format_exc()) escaped_tb = tools.html_escape(traceback.format_exc())
self.message_post( # pylint: disable=translation-required self.message_post( # pylint: disable=translation-required
body="<p>%s</p><pre>%s</pre>" body=f"<p>{_('Database backup failed.')}</p><pre>{escaped_tb}</pre>",
% (_("Database backup failed."), escaped_tb),
subtype_id=self.env.ref("auto_backup.mail_message_subtype_failure").id, subtype_id=self.env.ref("auto_backup.mail_message_subtype_failure").id,
) )
else: else:
@ -264,8 +263,8 @@ class DbBackup(models.Model):
_logger.exception("Cleanup of old database backups failed: %s") _logger.exception("Cleanup of old database backups failed: %s")
escaped_tb = tools.html_escape(traceback.format_exc()) escaped_tb = tools.html_escape(traceback.format_exc())
self.message_post( # pylint: disable=translation-required self.message_post( # pylint: disable=translation-required
body="<p>%s</p><pre>%s</pre>" body=f"<p>{_('Cleanup of old database backups failed.')}</p>"
% (_("Cleanup of old database backups failed."), escaped_tb), f"<pre>{escaped_tb}</pre>",
subtype_id=self.env.ref("auto_backup.failure").id, subtype_id=self.env.ref("auto_backup.failure").id,
) )
else: else:

View File

@ -1,6 +1,6 @@
- On larger databases, it is possible that backups will die due to Odoo - On larger databases, it is possible that backups will die due to Odoo
server settings. In order to circumvent this without frivolously server settings. In order to circumvent this without frivolously
changing settings, you need to run the backup from outside of the main changing settings, you need to run the backup from outside of the main
Odoo instance. How to do this is outlined in [this blog Odoo instance. How to do this (for version 9.0) was outlined in [this blog
post](https://blog.laslabs.com/2016/10/running-python-scripts-within-odoos-environment/). post](https://web.archive.org/web/20240805225230/https://blog.laslabs.com/2016/10/running-python-scripts-within-odoos-environment/).
- Backups won't work if list_db=False is configured in the instance. - Backups won't work if list_db=False is configured in the instance.

View File

@ -462,7 +462,8 @@ manually execute the selected processes.</p>
<li>On larger databases, it is possible that backups will die due to Odoo <li>On larger databases, it is possible that backups will die due to Odoo
server settings. In order to circumvent this without frivolously server settings. In order to circumvent this without frivolously
changing settings, you need to run the backup from outside of the main changing settings, you need to run the backup from outside of the main
Odoo instance. How to do this is outlined in <a class="reference external" href="https://blog.laslabs.com/2016/10/running-python-scripts-within-odoos-environment/">this blog Odoo instance. How to do this (for version 9.0) was outlined in <a class="reference external" href="https://web.archive.org/web/20240805225230/https://blog.laslabs.com/2016/10/running-python-scripts-within-odoos-environment/">this
blog
post</a>.</li> post</a>.</li>
<li>Backups wont work if list_db=False is configured in the instance.</li> <li>Backups wont work if list_db=False is configured in the instance.</li>
</ul> </ul>

View File

@ -12,7 +12,8 @@ from unittest.mock import PropertyMock, patch
from odoo import tools from odoo import tools
from odoo.exceptions import UserError from odoo.exceptions import UserError
from odoo.tests import common
from odoo.addons.base.tests.common import BaseCommon
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try: try:
@ -27,13 +28,14 @@ class_name = "%s.DbBackup" % model
class TestConnectionException(pysftp.ConnectionException): class TestConnectionException(pysftp.ConnectionException):
def __init__(self): def __init__(self):
super(TestConnectionException, self).__init__("test", "test") super().__init__("test", "test")
class TestDbBackup(common.TransactionCase): class TestDbBackup(BaseCommon):
def setUp(self): @classmethod
super(TestDbBackup, self).setUp() def setUpClass(cls):
self.Model = self.env["db.backup"] super().setUpClass()
cls.Model = cls.env["db.backup"]
@contextmanager @contextmanager
def mock_assets(self): def mock_assets(self):
@ -77,13 +79,7 @@ class TestDbBackup(common.TransactionCase):
"""It should create proper SFTP URI""" """It should create proper SFTP URI"""
rec_id = self.new_record() rec_id = self.new_record()
self.assertEqual( self.assertEqual(
"sftp://%(user)s@%(host)s:%(port)s%(folder)s" f"sftp://{self.vals['sftp_user']}@{self.vals['sftp_host']}:{self.vals['sftp_port']}{self.vals['folder']}",
% {
"user": self.vals["sftp_user"],
"host": self.vals["sftp_host"],
"port": self.vals["sftp_port"],
"folder": self.vals["folder"],
},
rec_id.name, rec_id.name,
) )

View File

@ -12,49 +12,56 @@
class="oe_highlight" class="oe_highlight"
/> />
</header> </header>
<div class="oe_title"> <sheet>
<h1> <div class="oe_title">
<field name="name" /> <h1>
</h1> <field name="name" />
</div> </h1>
<group string="Basic backup configuration">
<field name="folder" />
<field name="days_to_keep" />
<field name="method" />
<field name="backup_format" />
</group>
<div attrs="{'invisible': [('method', '!=', 'sftp')]}">
<div class="bg-warning">
<h3>Warning:</h3>
Use SFTP with caution! This writes files to external servers under the path you specify.
</div> </div>
<group string="SFTP Settings"> <group string="Basic backup configuration">
<field name="sftp_host" placeholder="sftp.example.com" /> <field name="folder" />
<field name="sftp_port" /> <field name="days_to_keep" />
<field name="sftp_user" placeholder="john" /> <field name="method" />
<field name="sftp_password" /> <field name="backup_format" />
<field
name="sftp_private_key"
placeholder="/home/odoo/.ssh/id_rsa"
/>
<button
name="action_sftp_test_connection"
type="object"
string="Test SFTP Connection"
icon="fa-television"
/>
</group> </group>
</div> <div invisible="method != 'sftp'">
<separator string="Help" colspan="2" /> <div class="bg-warning">
<div> <h3>Warning:</h3>
Automatic backups of the database can be scheduled as follows: Use SFTP with caution! This writes files to external servers under the path you specify.
<ol> </div>
<li <group string="SFTP Settings">
>Go to Settings / Technical / Automation / Scheduled Actions.</li> <field name="sftp_host" placeholder="sftp.example.com" />
<li>Search the action named 'Backup scheduler'.</li> <field name="sftp_port" />
<li <field name="sftp_user" placeholder="john" />
>Set the scheduler to active and fill in how often you want backups generated.</li> <field name="sftp_password" />
</ol> <field
name="sftp_private_key"
placeholder="/home/odoo/.ssh/id_rsa"
/>
<button
name="action_sftp_test_connection"
type="object"
string="Test SFTP Connection"
icon="fa-television"
/>
</group>
</div>
<separator string="Help" colspan="2" />
<div>
Automatic backups of the database can be scheduled as follows:
<ol>
<li
>Go to Settings / Technical / Automation / Scheduled Actions.</li>
<li>Search the action named 'Backup scheduler'.</li>
<li
>Set the scheduler to active and fill in how often you want backups generated.</li>
</ol>
</div>
</sheet>
<!-- Chatter -->
<div class="oe_chatter">
<field name="message_follower_ids" groups="base.group_user" />
<field name="message_ids" />
</div> </div>
</form> </form>
</field> </field>