Skip to content

Commit 4e23e3b

Browse files
committed
[ADD] auto_backup_fs_file: introduce Auto Backup Fs File module with initial files and configurations
1 parent f4a241d commit 4e23e3b

25 files changed

Lines changed: 1227 additions & 0 deletions

auto_backup_fs_file/README.rst

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
===================
2+
Auto Backup Fs File
3+
===================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:0b8048c71fd406f44c43adaa9fc156284a3b2ed3a70c0a026e7245ef182cc23d
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Alpha
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
20+
:target: https://github.com/OCA/server-tools/tree/17.0/auto_backup_fs_file
21+
:alt: OCA/server-tools
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/server-tools-17-0/server-tools-17-0-auto_backup_fs_file
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module enhances the database backup functionality in Odoo by
32+
introducing support for storing backups as files using the ``fsspec``
33+
library. It is designed to address the need for reliable and flexible
34+
backup solutions, enabling businesses to safeguard their data by storing
35+
backups on various filesystems, including cloud storage providers,
36+
network drives, and local secure storage.
37+
38+
By integrating with the ``fs_file`` addon from the OCA storage
39+
repository, this module allows users to automate the backup process and
40+
store the resulting files in a configured filesystem. It provides an
41+
easy-to-use interface for configuring backup methods, managing stored
42+
backups, and ensuring data integrity for disaster recovery or
43+
multi-environment setups.
44+
45+
.. IMPORTANT::
46+
This is an alpha version, the data model and design can change at any time without warning.
47+
Only for development or testing purpose, do not use in production.
48+
`More details on development status <https://odoo-community.org/page/development-status>`_
49+
50+
**Table of contents**
51+
52+
.. contents::
53+
:local:
54+
55+
Use Cases / Context
56+
===================
57+
58+
BUSINESS NEED: This module addresses the critical need for safeguarding
59+
Odoo instance data by enabling automated backups to a filesystem
60+
supported by the ``fsspec`` library. Businesses often require reliable
61+
and accessible backup solutions to ensure data integrity and recovery in
62+
case of system failures or data loss. This module is particularly useful
63+
in contexts where organizations need to store backups on cloud storage,
64+
network drives, or other custom filesystems supported by ``fsspec``.
65+
66+
Practical examples include:
67+
68+
- Backing up Odoo data to cloud storage providers like AWS S3, Google
69+
Cloud Storage, or Azure Blob Storage.
70+
- Storing backups on a secure local or remote filesystem for disaster
71+
recovery purposes.
72+
- Automating backup processes in multi-environment setups, such as
73+
multi-company or multi-website configurations.
74+
75+
APPROACH: The module extends the backup functionality from the
76+
``auto_backup`` module by introducing a method that allows storing the
77+
resulting backup using an ``fsspec`` implementation. This is achieved
78+
through the integration of the ``fs_file`` from `storage
79+
repository <https://github.com/OCA/storage>`__. The module leverages the
80+
``fsspec`` library to provide a flexible and extensible interface for
81+
interacting with various filesystems. It automates the backup process by
82+
exporting Odoo instance data and storing it in the specified filesystem.
83+
Additionally, it allows users to download the backups for local storage
84+
or further processing.
85+
86+
USEFUL INFORMATION:
87+
88+
- **Dependencies**: This module depends on the ``fsspec`` library, its
89+
relevant filesystem implementations, and the ``fs_file`` addon from
90+
OCA/storage. Ensure the required ``fsspec`` plugins are installed for
91+
your target filesystem.
92+
93+
Installation
94+
============
95+
96+
This addon itself does not introduce any dependencies, but its
97+
dependencies may require additional packages.:wa
98+
99+
Configuration
100+
=============
101+
102+
1. **Review Documentation for Dependencies** Before configuring the
103+
module, ensure you have reviewed the documentation for the following
104+
modules:
105+
106+
- ``fs_attachment``
107+
- ``fs_storage`` These modules provide the necessary setup for file
108+
storage and attachment handling.
109+
110+
2. **Configure File Storage**
111+
112+
- Navigate to **Settings** > **Technical** > **FS Storage**.
113+
- Create or select an existing storage configuration.
114+
- Ensure the storage is properly set up and tested for accessibility.
115+
116+
3. **Link Backup File field to Storage**
117+
118+
- While configuring the file storage in **Settings** > **Technical** >
119+
**FS Storage**, ensure that the ``backup_file`` from the
120+
``db.backup.fs.file`` model is listed under the ``Field`` field.
121+
- This step is part of the storage configuration process.
122+
- Save the changes after verifying the setup.
123+
124+
.. image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/auto_backup_fs_file/images/file_storage_configuration.png
125+
:alt: Example of File Storage Configuration
126+
127+
4. **Verify Configuration**
128+
129+
- Perform a test backup to ensure the files are being stored in the
130+
correct location.
131+
- Check the logs for any errors or warnings.
132+
133+
By following these steps, you will ensure that the module is properly
134+
configured for storing backups in the desired file storage system.
135+
136+
Usage
137+
=====
138+
139+
This module extends the functionality of the database backup system in
140+
Odoo by introducing a new backup method: **Fs File**. This method allows
141+
storing database backups as files using an FSSPEC implementation.
142+
143+
How to Use the Module
144+
---------------------
145+
146+
1. Configure the Backup Method
147+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
148+
149+
1. Navigate to **Settings** > **Technical** > **Database Structure** >
150+
**Automated Backups**.
151+
2. Create or edit a backup configuration.
152+
3. In the **Backup Method** field, select **Fs File**.
153+
4. Configure other fields as needed, such as the backup format and
154+
retention settings.
155+
5. Save the configuration.
156+
157+
2. Perform a Backup
158+
~~~~~~~~~~~~~~~~~~~
159+
160+
1. From the list of backup configurations, select the one configured
161+
with the **Fs File** method.
162+
2. Click the **Backup Now** button to initiate the backup process.
163+
3. The backup will be stored as a file in the configured FSSPEC storage.
164+
165+
3. View Fs File Backups
166+
~~~~~~~~~~~~~~~~~~~~~~~
167+
168+
1. Open the backup configuration form view.
169+
2. In the top-right corner, you will see a **Backups** stat button (if
170+
backups exist).
171+
3. Click the **Backups** button to view the list of Fs File backups
172+
associated with the configuration.
173+
174+
4. Manage Fs File Backups
175+
~~~~~~~~~~~~~~~~~~~~~~~~~
176+
177+
- In the Fs File backups list view, you can see details such as the
178+
backup filename and associated database backup configuration.
179+
- Use this view to manage or download backups as needed.
180+
181+
Screenshots
182+
~~~~~~~~~~~
183+
184+
- **Backup Configuration Form View** |Backup Configuration Form|
185+
186+
- **Fs File Backups List View** |Fs File Backups List|
187+
188+
Notes
189+
~~~~~
190+
191+
- Ensure that the FSSPEC storage is properly configured before using
192+
the **Fs File** method.
193+
- This module adds a new stat button in the backup configuration form
194+
view to quickly access Fs File backups.
195+
196+
.. |Backup Configuration Form| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/auto_backup_fs_file/static/description/db_backup_form_view.png
197+
.. |Fs File Backups List| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/auto_backup_fs_file/static/description/db_backup_fs_file_tree_view.png
198+
199+
Bug Tracker
200+
===========
201+
202+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
203+
In case of trouble, please check there if your issue has already been reported.
204+
If you spotted it first, help us to smash it by providing a detailed and welcomed
205+
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20auto_backup_fs_file%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
206+
207+
Do not contact contributors directly about support or help with technical issues.
208+
209+
Credits
210+
=======
211+
212+
Authors
213+
-------
214+
215+
* Binhex
216+
217+
Contributors
218+
------------
219+
220+
- Rolando Pérez Rebollo r.perez@binhex.cloud
221+
222+
Other credits
223+
-------------
224+
225+
The development of this module has been financially supported by:
226+
227+
- Binhex
228+
229+
Maintainers
230+
-----------
231+
232+
This module is maintained by the OCA.
233+
234+
.. image:: https://odoo-community.org/logo.png
235+
:alt: Odoo Community Association
236+
:target: https://odoo-community.org
237+
238+
OCA, or the Odoo Community Association, is a nonprofit organization whose
239+
mission is to support the collaborative development of Odoo features and
240+
promote its widespread use.
241+
242+
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/17.0/auto_backup_fs_file>`_ project on GitHub.
243+
244+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

auto_backup_fs_file/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2025 r.perez@binhex.cloud
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Auto Backup Fs File",
6+
"summary": """Store backups using some FSSPEC implementation""",
7+
"version": "17.0.1.0.0",
8+
"license": "AGPL-3",
9+
"author": "Binhex,Odoo Community Association (OCA)",
10+
"category": "Tools",
11+
"website": "https://github.com/OCA/server-tools",
12+
"depends": ["auto_backup", "fs_file", "mail"],
13+
"development_status": "Alpha",
14+
"data": [
15+
"data/mail_activity_type_data.xml",
16+
"data/fs_storage_data.xml",
17+
"security/ir.model.access.csv",
18+
"views/db_backup_views.xml",
19+
"views/db_backup_fs_file_views.xml",
20+
],
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!-- Copyright 2025 Binhex
3+
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
4+
<odoo noupdate="1">
5+
<record id="fs_storage_auto_backup" model="fs.storage">
6+
<field name="name">Odoo Filesystem Auto Backups Backend</field>
7+
<field name="protocol">odoofs</field>
8+
<field name="code">odoofs</field>
9+
<field
10+
name="field_xmlids"
11+
>auto_backup_fs_file.field_db_backup_fs_file__backup_file</field>
12+
</record>
13+
</odoo>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!-- Copyright 2025 Binhex
3+
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
4+
<odoo noupdate="1">
5+
<record id="mail_act_download_backup" model="mail.activity.type">
6+
<field name="name">Download Backup</field>
7+
<field name="icon">fa-download</field>
8+
<field name="res_model">db.backup.fs.file</field>
9+
</record>
10+
</odoo>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import db_backup_fs_file
2+
from . import db_backup
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2025 Binhex
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import _, api, fields, models
5+
from odoo.service import db
6+
7+
from odoo.addons.fs_file.fields import FSFileValue
8+
9+
10+
class DbBackup(models.Model):
11+
_inherit = "db.backup"
12+
13+
method = fields.Selection(
14+
selection_add=[("fs_file", "Fs File")], ondelete={"fs_file": "cascade"}
15+
)
16+
17+
fs_file_backup_ids = fields.One2many(
18+
comodel_name="db.backup.fs.file",
19+
inverse_name="db_backup_id",
20+
string="Fs File Backups",
21+
)
22+
23+
fs_file_backup_count = fields.Integer(compute="_compute_fs_file_backup_count")
24+
25+
responsible_id = fields.Many2one("res.users", help="User to be notified.")
26+
27+
@api.depends("fs_file_backup_ids")
28+
def _compute_fs_file_backup_count(self):
29+
"""Compute the count of fs_file backups."""
30+
for record in self:
31+
record.fs_file_backup_count = len(record.fs_file_backup_ids)
32+
33+
def action_backup(self):
34+
"""Override the action_backup method to add the fs_file method."""
35+
fs_backups = self.filtered(lambda it: it.method == "fs_file")
36+
dbname = self.env.cr.dbname
37+
for fs_backup in fs_backups:
38+
with fs_backup.backup_log():
39+
filename = self.filename(
40+
fields.Datetime.now(), ext=fs_backup.backup_format
41+
)
42+
backup = self.env["db.backup.fs.file"].create(
43+
{
44+
"name": filename,
45+
"db_backup_id": fs_backup.id,
46+
"backup_file": FSFileValue(
47+
name=filename,
48+
value=b"init file",
49+
),
50+
}
51+
)
52+
with backup.backup_file.open("wb") as f:
53+
db.dump_db(dbname, f, fs_backup.backup_format)
54+
user_to_notify = fs_backup.responsible_id or self.env.user
55+
backup.activity_schedule(
56+
"auto_backup_fs_file.mail_act_download_backup",
57+
date_deadline=fields.Date.today(),
58+
summary=_("Database backup is ready to download."),
59+
user_id=user_to_notify.id,
60+
)
61+
res = super().action_backup()
62+
return res
63+
64+
def action_open_fs_backups_view(self):
65+
self.ensure_one()
66+
action = self.env["ir.actions.actions"]._for_xml_id(
67+
"auto_backup_fs_file.db_backup_fs_file_act_window"
68+
)
69+
action["domain"] = [("db_backup_id", "=", self.id)]
70+
return action
71+
72+
def cleanup(self):
73+
"""Extend cleanup to fs_file backups."""
74+
for db_backup_conf in self.filtered(
75+
lambda record: record.method == "fs_file" and record.days_to_keep
76+
):
77+
with db_backup_conf.cleanup_log():
78+
to_delete = db_backup_conf.fs_file_backup_ids.filtered(
79+
"storage_time_exceeded"
80+
)
81+
for backup in to_delete:
82+
backup.storage.fs.rm_file(backup.backup_file.name)
83+
to_delete.unlink()
84+
res = super().cleanup()
85+
return res

0 commit comments

Comments
 (0)