Skip to content

18.0 #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 18.0
Choose a base branch
from
Open

18.0 #281

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion auto_backup/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'author': "Yenthe Van Ginneken",
'website': "http://www.odoo.yenthevg.com",
'category': 'Administration',
'version': '17.0.0.1',
'version': '18.0.0.1',
'installable': True,
'license': 'LGPL-3',
'module_type': 'official',
Expand Down
7 changes: 1 addition & 6 deletions auto_backup/data/backup_data.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" ?>
<odoo>
<data noupdate="1">
<odoo noupdate="1">
<record id="backup_scheduler" model="ir.cron">
<field name="name">Backup scheduler</field>
<field name="model_id" ref="model_db_backup"/>
Expand All @@ -9,10 +8,6 @@
<field name="priority">5</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="active">False</field>
<field name="doall">False</field>
</record>
</data>
</odoo>

8 changes: 5 additions & 3 deletions auto_backup/models/db_backup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import os
import datetime
import time
Expand All @@ -7,6 +6,7 @@
import tempfile
import subprocess
from odoo import models, fields, api, tools, _
from odoo.tools.misc import exec_pg_environ, find_pg_tool
from odoo.exceptions import UserError, AccessDenied
import odoo

Expand Down Expand Up @@ -272,9 +272,11 @@ def schedule_backup(self):
# call. Since this function is called from the cron and since we have these security checks on model and on user_id
# its pretty impossible to hack any way to take a backup. This allows us to disable the Odoo database manager
# which is a MUCH safer way

def _take_dump(self, db_name, stream, model, backup_format='zip'):
"""Dump database `db` into file-like object `stream` if stream is None
return a file object with the dump """
print(stream)

cron_user_id = self.env.ref('auto_backup.backup_scheduler').user_id.id
if self._name != 'db.backup' or cron_user_id != self.env.user.id:
Expand All @@ -283,8 +285,8 @@ def _take_dump(self, db_name, stream, model, backup_format='zip'):

_logger.info('DUMP DB: %s format %s', db_name, backup_format)

cmd = [tools.find_pg_tool('pg_dump'), '--no-owner', db_name]
env = tools.exec_pg_environ()
cmd = [find_pg_tool('pg_dump'), '--no-owner', db_name]
env = exec_pg_environ()

if backup_format == 'zip':
with tempfile.TemporaryDirectory() as dump_dir:
Expand Down
14 changes: 7 additions & 7 deletions auto_backup/views/backup_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,27 @@
</field>
</record>

<record id="view_backup_config_tree" model="ir.ui.view">
<field name="name">db.backup.tree</field>
<record id="view_backup_config_list" model="ir.ui.view">
<field name="name">db.backup.list</field>
<field name="model">db.backup</field>
<field name="type">tree</field>
<field name="type">list</field>
<field name="arch" type="xml">
<tree>
<list>
<field name='host'/>
<field name='port'/>
<field name='name'/>
<field name='folder'/>
<field name="autoremove"/>
<field name="sftp_host"/>
</tree>
</list>
</field>
</record>

<record id="action_backup" model="ir.actions.act_window">
<field name="name">Configure back-ups</field>
<field name="res_model">db.backup</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_backup_config_tree"/>
<field name="view_mode">list,form</field>
<field name="view_id" ref="view_backup_config_list"/>
</record>

<menuitem id="auto_backup_menu" name="Back-ups" parent="base.menu_custom"/>
Expand Down