Skip to content

Commit

Permalink
[MIG] auto_backup: Migrate to v9
Browse files Browse the repository at this point in the history
* Add self.ensure_ones
* Add test coverage
  • Loading branch information
lasley authored and rpinset committed Jun 28, 2024
1 parent ebe686b commit c7d87ea
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 78 deletions.
20 changes: 15 additions & 5 deletions auto_backup/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,24 @@ manually execute the selected processes.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/8.0
:target: https://runbot.odoo-community.org/runbot/149/10.0

Known issues / Roadmap
======================

* On larger databases, it is possible that backups will die due to Odoo server
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
<https://blog.laslabs.com/2016/10/running-python-scripts-within-odoos-environment/>`_.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/server-tools/issues/new?body=module:%20auto_backup%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======
Expand All @@ -89,6 +98,7 @@ Contributors
* Yenthe Van Ginneken <yenthe.vanginneken@vanroey.be>
* Alessio Gerace <alessio.gerace@agilebg.com>
* Jairo Llopis <yajo.sk8@gmail.com>
* Dave Lasley <dave@laslabs.com>

Maintainer
----------
Expand Down
19 changes: 12 additions & 7 deletions auto_backup/__openerp__.py → auto_backup/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
{
"name": "Database Auto-Backup",
"summary": "Backups database",
"version": "8.0.1.0.1",
"version": "10.0.1.0.0",
"author": (
"VanRoey.be - Yenthe Van Ginneken, Agile Business Group,"
" Grupo ESOC Ingenier??a de Servicios,"
" Odoo Community Association (OCA)"
"Yenthe Van Ginneken, "
"Agile Business Group, "
"Grupo ESOC Ingenier??a de Servicios, "
"LasLabs, "
"Odoo Community Association (OCA)"
),
'license': "AGPL-3",
"website": "http://www.vanroey.be/applications/bedrijfsbeheer/odoo",
"category": "Tools",
"depends": ['email_template'],
"demo": [],
"depends": [
'base_setup',
'mail',
],
"data": [
"data/backup_data.yml",
"data/ir_cron.xml",
"data/mail_message_subtype.xml",
"security/ir.model.access.csv",
"view/db_backup_view.xml",
],
Expand Down
28 changes: 0 additions & 28 deletions auto_backup/data/backup_data.yml

This file was deleted.

18 changes: 18 additions & 0 deletions auto_backup/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<odoo noupdate="1">

<record id="ir_cron_backup_scheduler_0" model="ir.cron">
<field name="name">Backup Scheduler</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="nextcall"
eval="(datetime.now() + timedelta(days=1)).strftime('%Y-%m-%d 02:00:00')"
/>
<field name="model">db.backup</field>
<field name="function">action_backup_all</field>
</record>

</odoo>
19 changes: 19 additions & 0 deletions auto_backup/data/mail_message_subtype.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<odoo noupdate="1">

<record id="mail_message_subtype_success" model="mail.message.subtype">
<field name="name">Backup Successful</field>
<field name="description">Database backup succeeded.</field>
<field name="res_model">db.backup</field>
<field name="default" eval="False" />
</record>

<record id="mail_message_subtype_failure" model="mail.message.subtype">
<field name="name">Backup Failed</field>
<field name="description">Database backup failed.</field>
<field name="res_model">db.backup</field>
<field name="default" eval="True" />
</record>

</odoo>
10 changes: 6 additions & 4 deletions auto_backup/models/db_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from contextlib import contextmanager
from datetime import datetime, timedelta
from glob import iglob
from openerp import exceptions, models, fields, api, _, tools
from openerp.service import db
from odoo import exceptions, models, fields, api, _, tools
from odoo.service import db
import logging
_logger = logging.getLogger(__name__)
try:
import pysftp
except ImportError:
except ImportError: # pragma: no cover
_logger.debug('Cannot import pysftp')


Expand Down Expand Up @@ -107,8 +107,8 @@ def _compute_name(self):
rec.name = "sftp://%s@%s:%d%s" % (
rec.sftp_user, rec.sftp_host, rec.sftp_port, rec.folder)

@api.constrains("folder", "method")
@api.multi
@api.constrains("folder", "method")
def _check_folder(self):
"""Do not use the filestore or you will backup your backups."""
for s in self:
Expand Down Expand Up @@ -235,6 +235,7 @@ def cleanup(self):
@contextmanager
def cleanup_log(self):
"""Log a possible cleanup failure."""
self.ensure_one()
try:
_logger.info("Starting cleanup process after database backup: %s",
self.name)
Expand Down Expand Up @@ -263,6 +264,7 @@ def filename(self, when):
@api.multi
def sftp_connection(self):
"""Return a new SFTP connection with found parameters."""
self.ensure_one()
params = {
"host": self.sftp_host,
"username": self.sftp_user,
Expand Down
2 changes: 1 addition & 1 deletion auto_backup/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# ?? 2016 Grupo ESOC Ingenier??a de Servicios, S.L.U. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import test_auto_backup
from . import test_db_backup
28 changes: 0 additions & 28 deletions auto_backup/tests/test_auto_backup.py

This file was deleted.

Loading

0 comments on commit c7d87ea

Please sign in to comment.