Skip to content
Open
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
40 changes: 18 additions & 22 deletions auto_backup/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

====================
Database Auto-Backup
====================
Expand All @@ -17,7 +13,7 @@ Database Auto-Backup
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
Expand Down Expand Up @@ -46,7 +42,7 @@ Before installing this module, you need to execute:

::

pip3 install pysftp==0.2.9
pip3 install "paramiko<4.0.0"

Configuration
=============
Expand All @@ -71,7 +67,7 @@ Keep your data safe, through an SSH tunnel!
Want to go even further and write your backups to an external server?
You can with this module! Specify the credentials to the server, specify
a path and everything will be backed up automatically. This is done
through an SSH (encrypted) tunnel, thanks to pysftp, so your data is
through an SSH (encrypted) tunnel, thanks to Paramiko, so your data is
safe!

Test connection
Expand Down Expand Up @@ -108,12 +104,12 @@ manually execute the selected processes.
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/>`__.
- Backups won't work if list_db=False is configured in the instance.
- 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/>`__.
- Backups won't work if list_db=False is configured in the instance.

Bug Tracker
===========
Expand All @@ -140,15 +136,15 @@ Authors
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>
- Andrea Stirpe <a.stirpe@onestein.nl>
- Aitor Bouzas <aitor.bouzas@adaptivecity.com>
- Simone Vanin <simone.vanin@agilebg.com>
- Vu Nguyen Anh <vuna2004@gmail.com>
- Alex Comba <alex.comba@agilebg.com>
- Yenthe Van Ginneken <yenthe.vanginneken@vanroey.be>
- Alessio Gerace <alessio.gerace@agilebg.com>
- Jairo Llopis <yajo.sk8@gmail.com>
- Dave Lasley <dave@laslabs.com>
- Andrea Stirpe <a.stirpe@onestein.nl>
- Aitor Bouzas <aitor.bouzas@adaptivecity.com>
- Simone Vanin <simone.vanin@agilebg.com>
- Vu Nguyen Anh <vuna2004@gmail.com>
- Alex Comba <alex.comba@agilebg.com>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion auto_backup/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
"view/db_backup_view.xml",
],
"installable": True,
"external_dependencies": {"python": ["paramiko<4.0.0", "pysftp", "cryptography"]},
"external_dependencies": {"python": ["paramiko<4.0.0", "cryptography"]},
}
55 changes: 42 additions & 13 deletions auto_backup/models/db_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from contextlib import contextmanager
from datetime import datetime, timedelta
from glob import iglob
from pathlib import PurePosixPath

import pysftp
import paramiko

from odoo import _, api, exceptions, fields, models, tools
from odoo.exceptions import UserError
Expand Down Expand Up @@ -129,9 +130,9 @@ def action_sftp_test_connection(self):
with self.sftp_connection():
raise UserError(_("Connection Test Succeeded!"))
except (
pysftp.CredentialException,
pysftp.ConnectionException,
pysftp.SSHException,
OSError,
paramiko.AuthenticationException,
paramiko.SSHException,
) as exc:
_logger.info("Connection Test Failed!", exc_info=True)
raise UserError(self.env._("Connection Test Failed!")) from exc
Expand Down Expand Up @@ -176,10 +177,7 @@ def action_backup(self):

with cached:
with rec.sftp_connection() as remote:
try:
remote.makedirs(rec.folder)
except pysftp.ConnectionException as exc:
_logger.exception(f"pysftp ConnectionException: {exc}")
rec._sftp_makedirs(remote, rec.folder)

# Copy cached backup to remote server
with remote.open(
Expand Down Expand Up @@ -270,22 +268,53 @@ def filename(when, ext="zip"):
when, ext="dump.zip" if ext == "zip" else ext
)

@contextmanager
def sftp_connection(self):
"""Return a new SFTP connection with found parameters."""
self.ensure_one()
params = {
"host": self.sftp_host,
"hostname": self.sftp_host,
"username": self.sftp_user,
"port": self.sftp_port,
"allow_agent": False,
"look_for_keys": False,
}
_logger.debug(
"Trying to connect to sftp://%(username)s@%(host)s:%(port)d", extra=params
"Trying to connect to sftp://%s@%s:%d",
self.sftp_user,
self.sftp_host,
self.sftp_port,
)
if self.sftp_private_key:
params["private_key"] = self.sftp_private_key
params["key_filename"] = self.sftp_private_key
if self.sftp_password:
params["private_key_pass"] = self.sftp_password
params["password"] = self.sftp_password
else:
params["password"] = self.sftp_password

return pysftp.Connection(**params)
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
sftp = None
try:
ssh.connect(**params)
sftp = ssh.open_sftp()
yield sftp
finally:
if sftp:
sftp.close()
ssh.close()

@staticmethod
def _sftp_makedirs(sftp, path):
"""Create a remote directory and its parents when missing."""
missing = []
current = PurePosixPath(path)
while current != current.parent:
try:
sftp.stat(str(current))
break
except FileNotFoundError:
missing.append(current)
current = current.parent
for directory in reversed(missing):
sftp.mkdir(str(directory))
2 changes: 1 addition & 1 deletion auto_backup/readme/INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Before installing this module, you need to execute:

pip3 install pysftp==0.2.9
pip3 install "paramiko<4.0.0"
2 changes: 1 addition & 1 deletion auto_backup/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and external backups should be kept, automatically!
Want to go even further and write your backups to an external server?
You can with this module! Specify the credentials to the server, specify
a path and everything will be backed up automatically. This is done
through an SSH (encrypted) tunnel, thanks to pysftp, so your data is
through an SSH (encrypted) tunnel, thanks to Paramiko, so your data is
safe!

## Test connection
Expand Down
54 changes: 24 additions & 30 deletions auto_backup/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Database Auto-Backup</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="database-auto-backup">
<h1 class="title">Database Auto-Backup</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="database-auto-backup">
<h1>Database Auto-Backup</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6069fbb878a731cb4ac25058910ed6564c72cfecbb647732f21616058b9d6453
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/18.0/auto_backup"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-auto_backup"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/18.0/auto_backup"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-auto_backup"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>A tool for all your back-ups, internal and external!</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand Down Expand Up @@ -408,82 +403,82 @@ <h1>Database Auto-Backup</h1>
</ul>
</div>
<div class="section" id="installation">
<h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
<p>Before installing this module, you need to execute:</p>
<pre class="literal-block">
pip3 install pysftp==0.2.9
pip3 install &quot;paramiko&lt;4.0.0&quot;
</pre>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
<p>Go to <em>Settings -&gt; Database Structure -&gt; Automated Backup</em> to create
your configurations for each database that you needed to backups.</p>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-3">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
<p>Keep your Odoo data safe with this module. Take automated back-ups,
remove them automatically and even write them to an external server
through an encrypted tunnel. You can even specify how long local backups
and external backups should be kept, automatically!</p>
<div class="section" id="connect-with-an-ftp-server">
<h3><a class="toc-backref" href="#toc-entry-4">Connect with an FTP Server</a></h3>
<h2><a class="toc-backref" href="#toc-entry-4">Connect with an FTP Server</a></h2>
<div class="section" id="keep-your-data-safe-through-an-ssh-tunnel">
<h4><a class="toc-backref" href="#toc-entry-5">Keep your data safe, through an SSH tunnel!</a></h4>
<h3><a class="toc-backref" href="#toc-entry-5">Keep your data safe, through an SSH tunnel!</a></h3>
<p>Want to go even further and write your backups to an external server?
You can with this module! Specify the credentials to the server, specify
a path and everything will be backed up automatically. This is done
through an SSH (encrypted) tunnel, thanks to pysftp, so your data is
through an SSH (encrypted) tunnel, thanks to Paramiko, so your data is
safe!</p>
</div>
</div>
<div class="section" id="test-connection">
<h3><a class="toc-backref" href="#toc-entry-6">Test connection</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Test connection</a></h2>
<div class="section" id="checks-your-credentials-in-one-click">
<h4><a class="toc-backref" href="#toc-entry-7">Checks your credentials in one click</a></h4>
<h3><a class="toc-backref" href="#toc-entry-7">Checks your credentials in one click</a></h3>
<p>Want to make sure if the connection details are correct and if Odoo can
automatically write them to the remote server? Simply click on the ‘Test
SFTP Connection’ button and you will get message telling you if
everything is OK, or what is wrong!</p>
</div>
</div>
<div class="section" id="e-mail-on-backup-failure">
<h3><a class="toc-backref" href="#toc-entry-8">E-mail on backup failure</a></h3>
<h2><a class="toc-backref" href="#toc-entry-8">E-mail on backup failure</a></h2>
<div class="section" id="stay-informed-of-problems-automatically">
<h4><a class="toc-backref" href="#toc-entry-9">Stay informed of problems, automatically!</a></h4>
<h3><a class="toc-backref" href="#toc-entry-9">Stay informed of problems, automatically!</a></h3>
<p>Do you want to know if the database backup succeeded or failed?
Subscribe to the corresponding backup setting notification type.</p>
</div>
</div>
<div class="section" id="run-backups-when-you-want">
<h3><a class="toc-backref" href="#toc-entry-10">Run backups when you want</a></h3>
<h2><a class="toc-backref" href="#toc-entry-10">Run backups when you want</a></h2>
<p>From the backups configuration list, press <em>More &gt; Execute backup(s)</em> to
manually execute the selected processes.</p>
<p><a class="reference external image-reference" href="https://runbot.odoo-community.org/runbot/149/11.0"><img alt="Try me on Runbot" src="https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas" /></a></p>
</div>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-11">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-11">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>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 <a class="reference external" href="https://blog.laslabs.com/2016/10/running-python-scripts-within-odoos-environment/">this blog
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
post</a>.</li>
<li>Backups won’t work if list_db=False is configured in the instance.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-12">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-12">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20auto_backup%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-13">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-13">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-14">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-14">Authors</a></h2>
<ul class="simple">
<li>Yenthe Van Ginneken</li>
<li>Agile Business Group</li>
Expand All @@ -493,7 +488,7 @@ <h3><a class="toc-backref" href="#toc-entry-14">Authors</a></h3>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-15">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-15">Contributors</a></h2>
<ul class="simple">
<li>Yenthe Van Ginneken &lt;<a class="reference external" href="mailto:yenthe.vanginneken&#64;vanroey.be">yenthe.vanginneken&#64;vanroey.be</a>&gt;</li>
<li>Alessio Gerace &lt;<a class="reference external" href="mailto:alessio.gerace&#64;agilebg.com">alessio.gerace&#64;agilebg.com</a>&gt;</li>
Expand All @@ -507,7 +502,7 @@ <h3><a class="toc-backref" href="#toc-entry-15">Contributors</a></h3>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-16">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-16">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -520,6 +515,5 @@ <h3><a class="toc-backref" href="#toc-entry-16">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
Loading
Loading