diff --git a/auto_database_backup/README.rst b/auto_database_backup/README.rst index aa53ac246..2aaa6b9bb 100644 --- a/auto_database_backup/README.rst +++ b/auto_database_backup/README.rst @@ -1,5 +1,5 @@ -Automatic Database Backup -========================= +Automatic Database Backup To Local Server, Remote Server, Google Drive And Dropbox +================================================================================== * Generate Database Backups and store to multiple locations Installation diff --git a/auto_database_backup/__init__.py b/auto_database_backup/__init__.py index d3c6c989e..a4a979205 100644 --- a/auto_database_backup/__init__.py +++ b/auto_database_backup/__init__.py @@ -3,7 +3,7 @@ # # Cybrosys Technologies Pvt. Ltd. # -# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Copyright (C) 2022-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions() # # You can modify it under the terms of the GNU LESSER @@ -19,3 +19,4 @@ # If not, see . from . import models +from . import wizard diff --git a/auto_database_backup/__manifest__.py b/auto_database_backup/__manifest__.py index c31cfe41f..12293d2b3 100644 --- a/auto_database_backup/__manifest__.py +++ b/auto_database_backup/__manifest__.py @@ -3,7 +3,7 @@ # # Cybrosys Technologies Pvt. Ltd. # -# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Copyright (C) 2022-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions() # # You can modify it under the terms of the GNU LESSER @@ -21,9 +21,9 @@ ############################################################################# { - 'name': "Automatic Database Backup", - 'version': '15.0.1.0.0', - 'summary': """Generate automatic backup of databases and store to local, google drive or remote server""", + 'name': "Automatic Database Backup To Local Server, Remote Server, Google Drive And Dropbox", + 'version': '15.0.2.0.1', + 'summary': """Generate automatic backup of databases and store to local, google drive, dropbox or remote server""", 'description': """This module has been developed for creating database backups automatically and store it to the different locations.""", 'author': "Cybrosys Techno Solutions", @@ -35,7 +35,8 @@ 'data': [ 'security/ir.model.access.csv', 'data/data.xml', - 'views/db_backup_configure_views.xml' + 'views/db_backup_configure_views.xml', + 'wizard/dropbox_authcode_wizard_views.xml' ], 'license': 'LGPL-3', 'images': ['static/description/banner.gif'], diff --git a/auto_database_backup/data/data.xml b/auto_database_backup/data/data.xml index f373ae0ce..2787ddd11 100644 --- a/auto_database_backup/data/data.xml +++ b/auto_database_backup/data/data.xml @@ -48,6 +48,9 @@ SFTP Server + + Dropbox + .

@@ -67,7 +70,10 @@ SFTP Server - + + Dropbox + +
Backup Path: @@ -79,6 +85,9 @@ + + +
Backup Type: @@ -127,7 +136,10 @@ SFTP Server - + + Dropbox + +
Backup Path: @@ -139,6 +151,9 @@ + + +
Backup Type: diff --git a/auto_database_backup/doc/RELEASE_NOTES.md b/auto_database_backup/doc/RELEASE_NOTES.md index ff8b062f2..d17f5d9fb 100644 --- a/auto_database_backup/doc/RELEASE_NOTES.md +++ b/auto_database_backup/doc/RELEASE_NOTES.md @@ -5,5 +5,8 @@ #### ADD - Initial commit for auto_database_backup - +#### 14.06.2022 +#### Version 15.0.1.0.1 +#### ADD +- Dropbox integration added. Backup can be stored in to dropbox. diff --git a/auto_database_backup/models/__init__.py b/auto_database_backup/models/__init__.py index 90120bcea..f71ffa785 100644 --- a/auto_database_backup/models/__init__.py +++ b/auto_database_backup/models/__init__.py @@ -3,7 +3,7 @@ # # Cybrosys Technologies Pvt. Ltd. # -# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Copyright (C) 2022-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions() # # You can modify it under the terms of the GNU LESSER diff --git a/auto_database_backup/models/db_backup_configure.py b/auto_database_backup/models/db_backup_configure.py index 28d587e74..b3a0f3a27 100644 --- a/auto_database_backup/models/db_backup_configure.py +++ b/auto_database_backup/models/db_backup_configure.py @@ -3,7 +3,7 @@ # # Cybrosys Technologies Pvt. Ltd. # -# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Copyright (C) 2022-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions() # # You can modify it under the terms of the GNU LESSER @@ -25,6 +25,8 @@ from odoo.exceptions import UserError, ValidationError import odoo from odoo.service import db +import dropbox + import datetime import os import paramiko @@ -53,21 +55,26 @@ class AutoDatabaseBackup(models.Model): ('local', 'Local Storage'), ('google_drive', 'Google Drive'), ('ftp', 'FTP'), - ('sftp', 'SFTP') + ('sftp', 'SFTP'), + ('dropbox', 'Dropbox') ], string='Backup Destination') backup_path = fields.Char(string='Backup Path', help='Local storage directory path') sftp_host = fields.Char(string='SFTP Host') sftp_port = fields.Char(string='SFTP Port', default=22) - sftp_user = fields.Char(string='SFTP User') - sftp_password = fields.Char(string='SFTP Password') + sftp_user = fields.Char(string='SFTP User', copy=False) + sftp_password = fields.Char(string='SFTP Password', copy=False) sftp_path = fields.Char(string='SFTP Path') ftp_host = fields.Char(string='FTP Host') ftp_port = fields.Char(string='FTP Port', default=21) - ftp_user = fields.Char(string='FTP User') - ftp_password = fields.Char(string='FTP Password') + ftp_user = fields.Char(string='FTP User', copy=False) + ftp_password = fields.Char(string='FTP Password', copy=False) ftp_path = fields.Char(string='FTP Path') + dropbox_client_id = fields.Char(string='Dropbox Client ID', copy=False) + dropbox_client_secret = fields.Char(string='Dropbox Client Secret', copy=False) + dropbox_refresh_token = fields.Char(string='Dropbox Refresh Token', copy=False) + is_dropbox_token_generated = fields.Boolean(string='Dropbox Token Generated', compute='_compute_is_dropbox_token_generated', copy=False) + dropbox_folder = fields.Char('Dropbox Folder') active = fields.Boolean(default=True) - save_to_drive = fields.Boolean() auto_remove = fields.Boolean(string='Remove Old Backups') days_to_remove = fields.Integer(string='Remove After', help='Automatically delete stored backups after this specified number of days') @@ -78,10 +85,48 @@ class AutoDatabaseBackup(models.Model): backup_filename = fields.Char(string='Backup Filename', help='For Storing generated backup filename') generated_exception = fields.Char(string='Exception', help='Exception Encountered while Backup generation') - @api.constrains('db_name', 'master_pwd') + @api.depends('dropbox_refresh_token') + def _compute_is_dropbox_token_generated(self): + """ + Set True if the dropbox refresh token is generated + """ + for rec in self: + rec.is_dropbox_token_generated = bool(rec.dropbox_refresh_token) + + def action_get_dropbox_auth_code(self): + """ + Open a wizard to setup dropbox Authorization code + """ + return { + 'type': 'ir.actions.act_window', + 'name': 'Dropbox Authorization Wizard', + 'res_model': 'dropbox.auth.wizard', + 'view_mode': 'form', + 'target': 'new', + } + + def get_dropbox_auth_url(self): + """ + Return dropbox authorization url + """ + dbx_auth = dropbox.oauth.DropboxOAuth2FlowNoRedirect(self.dropbox_client_id, self.dropbox_client_secret, + token_access_type='offline') + auth_url = dbx_auth.start() + return auth_url + + def set_dropbox_refresh_token(self, auth_code): + """ + Generate and set the dropbox refresh token from authorization code + """ + dbx_auth = dropbox.oauth.DropboxOAuth2FlowNoRedirect(self.dropbox_client_id, self.dropbox_client_secret, + token_access_type='offline') + outh_result = dbx_auth.finish(auth_code) + self.dropbox_refresh_token = outh_result.refresh_token + + @api.constrains('db_name') def _check_db_credentials(self): """ - Validate enetered database name and master password + Validate entered database name and master password """ database_list = db.list_dbs() if self.db_name not in database_list: @@ -133,7 +178,6 @@ class AutoDatabaseBackup(models.Model): """ records = self.search([]) mail_template_success = self.env.ref('auto_database_backup.mail_template_data_db_backup_successful') - print('mail template success', mail_template_success) mail_template_failed = self.env.ref('auto_database_backup.mail_template_data_db_backup_failed') for rec in records: backup_time = datetime.datetime.utcnow().strftime("%Y-%m-%d_%H-%M-%S") @@ -157,7 +201,6 @@ class AutoDatabaseBackup(models.Model): if backup_duration.days >= rec.days_to_remove: os.remove(file) if rec.notify_user: - print('success notify') mail_template_success.send_mail(rec.id, force_send=True) except Exception as e: rec.generated_exception = e @@ -265,3 +308,25 @@ class AutoDatabaseBackup(models.Model): _logger.info('Google Drive Exception: %s', e) if rec.notify_user: mail_template_failed.send_mail(rec.id, force_send=True) + # Dropbox backup + elif rec.backup_destination == 'dropbox': + temp = tempfile.NamedTemporaryFile(suffix='.%s' % rec.backup_format) + with open(temp.name, "wb+") as tmp: + odoo.service.db.dump_db(rec.db_name, tmp, rec.backup_format) + try: + dbx = dropbox.Dropbox(app_key=rec.dropbox_client_id, app_secret=rec.dropbox_client_secret, oauth2_refresh_token=rec.dropbox_refresh_token) + dropbox_destination = rec.dropbox_folder + '/' + backup_filename + dbx.files_upload(temp.read(), dropbox_destination) + if rec.auto_remove: + files = dbx.files_list_folder(rec.dropbox_folder) + file_entries = files.entries + expired_files = list(filter(lambda fl: (datetime.datetime.now() - fl.client_modified).days >= rec.days_to_remove, file_entries)) + for file in expired_files: + dbx.files_delete_v2(file.path_display) + if rec.notify_user: + mail_template_success.send_mail(rec.id, force_send=True) + except Exception as error: + rec.generated_exception = error + _logger.info('Dropbox Exception: %s', error) + if rec.notify_user: + mail_template_failed.send_mail(rec.id, force_send=True) diff --git a/auto_database_backup/security/ir.model.access.csv b/auto_database_backup/security/ir.model.access.csv index bd7799217..632a3360f 100644 --- a/auto_database_backup/security/ir.model.access.csv +++ b/auto_database_backup/security/ir.model.access.csv @@ -1,2 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_db_backup_configure,access.db.backup.configure,model_db_backup_configure,base.group_user,1,1,1,1 \ No newline at end of file +access_db_backup_configure,access.db.backup.configure,model_db_backup_configure,base.group_user,1,1,1,1 +access_dropbox_auth_wizard,access.dropbox.auth.wizard,model_dropbox_auth_wizard,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/auto_database_backup/static/description/assets/icons/f-alarm.png b/auto_database_backup/static/description/assets/icons/f-alarm.png new file mode 100644 index 000000000..4a4d3d2c8 Binary files /dev/null and b/auto_database_backup/static/description/assets/icons/f-alarm.png differ diff --git a/auto_database_backup/static/description/assets/icons/f-backup.png b/auto_database_backup/static/description/assets/icons/f-backup.png new file mode 100644 index 000000000..808708a3f Binary files /dev/null and b/auto_database_backup/static/description/assets/icons/f-backup.png differ diff --git a/auto_database_backup/static/description/assets/icons/f-dropbox.png b/auto_database_backup/static/description/assets/icons/f-dropbox.png new file mode 100644 index 000000000..c8885eb5a Binary files /dev/null and b/auto_database_backup/static/description/assets/icons/f-dropbox.png differ diff --git a/auto_database_backup/static/description/assets/icons/f-ftp.png b/auto_database_backup/static/description/assets/icons/f-ftp.png new file mode 100644 index 000000000..0f9d99cdd Binary files /dev/null and b/auto_database_backup/static/description/assets/icons/f-ftp.png differ diff --git a/auto_database_backup/static/description/assets/icons/f-google-drive.png b/auto_database_backup/static/description/assets/icons/f-google-drive.png new file mode 100644 index 000000000..cfb334951 Binary files /dev/null and b/auto_database_backup/static/description/assets/icons/f-google-drive.png differ diff --git a/auto_database_backup/static/description/assets/icons/f-remove-database.png b/auto_database_backup/static/description/assets/icons/f-remove-database.png new file mode 100644 index 000000000..d6550213d Binary files /dev/null and b/auto_database_backup/static/description/assets/icons/f-remove-database.png differ diff --git a/auto_database_backup/static/description/assets/icons/f-sftp.png b/auto_database_backup/static/description/assets/icons/f-sftp.png new file mode 100644 index 000000000..11d4ae53d Binary files /dev/null and b/auto_database_backup/static/description/assets/icons/f-sftp.png differ diff --git a/auto_database_backup/static/description/banner.gif b/auto_database_backup/static/description/banner.gif index d4eb732f7..57bfa2a33 100644 Binary files a/auto_database_backup/static/description/banner.gif and b/auto_database_backup/static/description/banner.gif differ diff --git a/auto_database_backup/static/description/index.html b/auto_database_backup/static/description/index.html index 54a4fe918..d80a2cfa2 100644 --- a/auto_database_backup/static/description/index.html +++ b/auto_database_backup/static/description/index.html @@ -1,35 +1,36 @@
+ style="padding: 4rem 1rem !important; background-color: #714B67 !important; height: 600px !important; border-radius: 20px !important;">

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #FFFFFF !important; font-size: 3.5rem !important; text-align: center !important;"> Automatic Database Backup

- Generate Automatic Back up of databases and store to local, google drive or remote server + style="font-family: 'Montserrat', sans-serif !important; font-weight: 300 !important; color: #FFFFFF !important; font-size: 1.4rem !important; text-align: center !important;"> + Generate Automatic Back up of databases and store to Local Storage, Google Drive, Dropbox And Remote + Server

- +

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.5rem !important;"> Explore this module

+ style="background-color: #f5f2f5 !important; border-radius: 10px !important; margin: 1rem !important; padding: 1.5em !important; height: 100px !important;">

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.2rem !important;"> Overview

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #714B67 !important; font-size: 0.9rem !important;"> Learn more about this module

@@ -42,13 +43,13 @@
+ style="background-color: #f5f2f5 !important; border-radius: 10px !important; margin: 1rem !important; padding: 1.5em !important; height: 100px !important;">

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.2rem !important;"> Features

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #714B67 !important; font-size: 0.9rem !important;"> View features of this module

@@ -60,13 +61,13 @@
+ style="background-color: #f5f2f5 !important; border-radius: 10px !important; margin: 1rem !important; padding: 1.5em !important; height: 100px !important;">

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.2rem !important;"> Screenshots

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #714B67 !important; font-size: 0.9rem !important;"> See key screenshots of this module

@@ -82,14 +83,14 @@

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.5rem !important;"> Overview

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important; line-height: 30px !important;"> This module helps to generate backups of your databases automatically on regular interval of times. The generated backups can be stored into local storage, ftp server, sftp server or Google Drive. User can enable auto remove option to automatically delete old backups. @@ -104,93 +105,125 @@

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.5rem !important;"> Features

-
- -
-
-

- Generate Database Backup

-

- Generate database backups on regular intervals.

+
+
+ +
+
+

+ Generate Database Backup

+

+ Generate database backups on regular intervals +

+
+
-
- -
-
-

- Store Backup to FTP Server

-

- Generated backup can be stored to remote FTP server.

+
+
+ +
+
+

+ Store Backup to FTP Server

+

+ Generated backup can be stored to remote FTP server. +

+
-
- -
-
-

- Store Backup to SFTP Server

-

- Generated backup can be stored to remote SFTP server.

+
+
+ +
+
+

+ Store Backup to SFTP Server

+

+ Generated backup can be stored to remote SFTP server. +

+
-
- -
-
-

- Store Backup to Google drive

-

- Generated backup can be stored to google drive.

+
+
+ +
+
+

+ Store Backup to Google Drive

+

+ Generated backup can be stored to Google Drive. +

+
-
- -
-
-

- Automatically remove old backups.

-

- Old backups files will be deleted automatically based on the obsolescence of backup.

+
+
+ +
+
+

+ Store Backup to Dropbox

+

+ Generated backup can be stored to Dropbox. +

+
@@ -403,18 +436,18 @@
+ style="border-top-left-radius:10px; border-top-right-radius:10px" + src="./assets/modules/5.png">
@@ -422,13 +455,14 @@
- - + style="left:-25px;width: 35px;color: #000;"> + + + +
@@ -440,12 +474,12 @@

Our Services


+ style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;"/>
+ style="background-color: #1dd1a1 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -455,7 +489,7 @@
+ style="background-color: #ff6b6b !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -465,7 +499,7 @@
+ style="background-color: #6462CD !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -476,7 +510,7 @@
+ style="background-color: #ffa801 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -487,7 +521,7 @@
+ style="background-color: #54a0ff !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -497,7 +531,7 @@
+ style="background-color: #6d7680 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -508,7 +542,7 @@
+ style="background-color: #786fa6 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -518,7 +552,7 @@
+ style="background-color: #f8a5c2 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -528,7 +562,7 @@
+ style="background-color: #e6be26 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -545,15 +579,14 @@

Our Industries


+ style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;"/>
+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;"> -
+
Trading

@@ -565,10 +598,9 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;"> -
+
POS

@@ -580,11 +612,10 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;"> -
+ width="48px"> +
Education

@@ -595,11 +626,10 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;"> -
+ width="48px"> +
Manufacturing

@@ -610,10 +640,9 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;"> -
+
E-commerce & Website

@@ -625,10 +654,9 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;"> -
+
Service Management

@@ -639,11 +667,10 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;"> -
+ width="48px"> +
Restaurant

@@ -654,10 +681,9 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;"> -
+
Hotel Management

@@ -679,32 +705,27 @@

Need Help?


+ style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;"/>
+ style="max-width:1540px; margin: 0 auto 2rem auto;">
-
+ -
+ -
- info@cybrosys.com + class="btn btn-block mb-2 deep_hover" + style="text-decoration: none; background-color: #25D366; color: #FFF; border-radius: 4px;">+91 8606827707
@@ -717,12 +738,12 @@
- +

+ style="margin-top: 3rem;background: linear-gradient(90deg, rgba(2,0,36,0) 0%, rgba(229,229,229,1) 33%, rgba(229,229,229,1) 58%, rgba(0,212,255,0) 100%); height: 2px; border-style: none;">
diff --git a/auto_database_backup/views/db_backup_configure_views.xml b/auto_database_backup/views/db_backup_configure_views.xml index 1509ad3bc..c84ad4370 100644 --- a/auto_database_backup/views/db_backup_configure_views.xml +++ b/auto_database_backup/views/db_backup_configure_views.xml @@ -50,6 +50,39 @@ + + +
+
+ + Refresh token set +
+
+ + No refresh token set +
+
+
+
+ +
+
+ +
+
+ + +