diff --git a/auto_backup/README.rst b/auto_backup/README.rst index c9c315054..7579fce45 100644 --- a/auto_backup/README.rst +++ b/auto_backup/README.rst @@ -62,6 +62,12 @@ Stay informed of problems, automatically! Do you want to know if the database backup succeeded or failed? Subscribe to the corresponding backup setting notification type. +Run backups when you want +------------------------- + +From the backups configuration list, press *More > Execute backup(s)* to +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 diff --git a/auto_backup/__init__.py b/auto_backup/__init__.py index c201f7b03..49f944b46 100644 --- a/auto_backup/__init__.py +++ b/auto_backup/__init__.py @@ -1,23 +1,7 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved -# $Id$ -# Copyright (C) 2015 Agile Business Group -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2004-2009 Tiny SPRL (). +# © 2015 Agile Business Group +# © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License GPL-3.0 or later (http://www.gnu.org/licenses/gpl.html). from . import models diff --git a/auto_backup/__openerp__.py b/auto_backup/__openerp__.py index 9f465f04b..b73af7cbe 100644 --- a/auto_backup/__openerp__.py +++ b/auto_backup/__openerp__.py @@ -1,24 +1,8 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved -# $Id$ -# Copyright (C) 2015 Agile Business Group -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2004-2009 Tiny SPRL (). +# © 2015 Agile Business Group +# © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License GPL-3.0 or later (http://www.gnu.org/licenses/gpl.html). { "name": "Database Auto-Backup", diff --git a/auto_backup/models/__init__.py b/auto_backup/models/__init__.py index 1f7194c4f..193305229 100644 --- a/auto_backup/models/__init__.py +++ b/auto_backup/models/__init__.py @@ -1,23 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved -# $Id$ -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2004-2009 Tiny SPRL (). +# © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License GPL-3.0 or later (http://www.gnu.org/licenses/gpl.html). from . import db_backup diff --git a/auto_backup/models/db_backup.py b/auto_backup/models/db_backup.py index cbf652cb1..891ee917c 100644 --- a/auto_backup/models/db_backup.py +++ b/auto_backup/models/db_backup.py @@ -1,23 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved -# Copyright 2015 Agile Business Group -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2004-2009 Tiny SPRL (). +# © 2015 Agile Business Group +# © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License GPL-3.0 or later (http://www.gnu.org/licenses/gpl.html). + import os import shutil import tempfile @@ -40,6 +26,7 @@ class DbBackup(models.Model): _inherit = "mail.thread" _sql_constraints = [ + ("name_unique", "UNIQUE(name)", "Cannot duplicate a configuration."), ("days_to_keep_positive", "CHECK(days_to_keep >= 0)", "I cannot remove backups from the future. Ask Doc for that."), ] @@ -104,10 +91,11 @@ class DbBackup(models.Model): @api.model def _default_folder(self): - """Default to ``backups`` folder inside current database datadir.""" + """Default to ``backups`` folder inside current server datadir.""" return os.path.join( - tools.config.filestore(self.env.cr.dbname), - "backups") + tools.config["data_dir"], + "backups", + self.env.cr.dbname) @api.multi @api.depends("folder", "method", "sftp_host", "sftp_port", "sftp_user") @@ -120,6 +108,18 @@ class DbBackup(models.Model): rec.name = "sftp://%s@%s:%d%s" % ( rec.sftp_user, rec.sftp_host, rec.sftp_port, rec.folder) + @api.constrains("folder", "method") + @api.multi + def _check_folder(self): + """Do not use the filestore or you will backup your backups.""" + for s in self: + if (s.method == "local" and + s.folder.startswith( + tools.config.filestore(self.env.cr.dbname))): + raise exceptions.ValidationError( + _("Do not save backups on your filestore, or you will " + "backup your backups too!")) + @api.multi def action_sftp_test_connection(self): """Check if the SFTP settings are correct.""" @@ -223,13 +223,14 @@ class DbBackup(models.Model): if rec.method == "local": for name in iglob(os.path.join(rec.folder, "*.dump.zip")): - if name < oldest: + if os.path.basename(name) < oldest: os.unlink(name) elif rec.method == "sftp": with rec.sftp_connection() as remote: for name in remote.listdir(rec.folder): - if name.endswith(".dump.zip") and name < oldest: + if (name.endswith(".dump.zip") and + os.path.basename(name) < oldest): remote.unlink(name) @api.multi diff --git a/auto_backup/tests/__init__.py b/auto_backup/tests/__init__.py index 01e81ba8a..ea27b998a 100644 --- a/auto_backup/tests/__init__.py +++ b/auto_backup/tests/__init__.py @@ -1,22 +1,7 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Agile Business Group -# Copyright (C) 2015 Alessio Gerace -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Agile Business Group +# © 2015 Alessio Gerace +# © 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 diff --git a/auto_backup/tests/test_auto_backup.py b/auto_backup/tests/test_auto_backup.py index a23089144..dac490aba 100644 --- a/auto_backup/tests/test_auto_backup.py +++ b/auto_backup/tests/test_auto_backup.py @@ -1,23 +1,8 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Agile Business Group -# Copyright (C) 2015 Alessio Gerace -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Agile Business Group +# © 2015 Alessio Gerace +# © 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). import os from datetime import datetime diff --git a/auto_backup/view/db_backup_view.xml b/auto_backup/view/db_backup_view.xml index bc9ad896a..d1f11e442 100644 --- a/auto_backup/view/db_backup_view.xml +++ b/auto_backup/view/db_backup_view.xml @@ -10,39 +10,33 @@

- + - +

Warning:

Use SFTP with caution! This writes files to external servers under the path you specify.
- - - - - -
- This configures the scheduler for automatic backup of the given database running on given host at given port on regular intervals. -
Automatic backups of the database can be scheduled as follows:
  1. Go to Settings / Technical / Automation / Scheduled Actions.
  2. @@ -90,5 +84,25 @@ action="action_backup_conf_form" id="backup_conf_menu"/> + + + Execute backup(s) + + + object.action_backup() + + + + + Execute backup(s) + + + action + + db.backup + client_action_multi + diff --git a/requirements.txt b/requirements.txt index c7ff0b87e..7d22f12ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ python-ldap unidecode validate_email + pysftp