Browse Source

Apr 18 [IMP] : Updated list_db false issue

pull/313/head
AjmalCybro 1 year ago
parent
commit
af59086a09
  1. 4
      auto_database_backup/__manifest__.py
  2. 10
      auto_database_backup/doc/RELEASE_NOTES.md
  3. 95
      auto_database_backup/models/db_backup_configure.py
  4. 35
      auto_database_backup/static/description/index.html

4
auto_database_backup/__manifest__.py

@ -22,7 +22,7 @@
{
'name': "Automatic Database Backup To Local Server, Remote Server,"
"Google Drive, Dropbox, Onedrive, Nextcloud and Amazon S3 Odoo17",
'version': '17.0.1.0.0',
'version': '17.0.3.0.1',
'live_test_url': 'https://youtu.be/Q2yMZyYjuTI',
'category': 'Extra Tools',
'summary': 'Odoo Database Backup, Automatic Backup, Database Backup, Automatic Backup,Database auto-backup, odoo backup'
@ -30,8 +30,8 @@
'remote server, Odoo17, Backup, Database, Odoo Apps',
'description': 'Odoo Database Backup, Database Backup, Automatic Backup, automatic database backup, odoo17, odoo apps,backup, automatic backup,odoo17 automatic database backup,backup google drive,backup dropbox, backup nextcloud, backup amazon S3, backup onedrive',
'author': "Cybrosys Techno Solutions",
'maintainer': 'Cybrosys Techno Solutions',
'company': 'Cybrosys Techno Solutions',
'maintainer': 'Cybrosys Techno Solutions',
'website': "https://www.cybrosys.com",
'depends': ['base', 'mail'],
'data': [

10
auto_database_backup/doc/RELEASE_NOTES.md

@ -12,4 +12,12 @@
#### Version 17.0.2.0.1
#### UPDT
- - Updated the database name check function which got access denied when list_db=False.
- Updated the database name check function which got access denied when list_db=False.
## Module <auto_database_backup>
#### 18.04.2024
#### Version 17.0.3.0.1
#### UPDT
- Fixed the errors while inputting list_db = False in odoo conf file.

95
auto_database_backup/models/db_backup_configure.py

@ -29,6 +29,8 @@ import nextcloud_client
import os
import paramiko
import requests
import shutil
import subprocess
import tempfile
import odoo
from datetime import timedelta
@ -37,6 +39,7 @@ from requests.auth import HTTPBasicAuth
from werkzeug import urls
from odoo import api, fields, models, _
from odoo.exceptions import UserError, ValidationError
from odoo.tools import find_pg_tool, exec_pg_environ
from odoo.http import request
from odoo.service import db
@ -616,7 +619,7 @@ class DbBackupConfigure(models.Model):
backup_file = os.path.join(rec.backup_path,
backup_filename)
f = open(backup_file, "wb")
odoo.service.db.dump_db(rec.db_name, f, rec.backup_format)
self.dump_data(rec.db_name, f, rec.backup_format)
f.close()
# Remove older backups
if rec.auto_remove:
@ -650,7 +653,7 @@ class DbBackupConfigure(models.Model):
ftp_server.mkd(rec.ftp_path)
ftp_server.cwd(rec.ftp_path)
with open(temp.name, "wb+") as tmp:
odoo.service.db.dump_db(rec.db_name, tmp,
self.dump_data(rec.db_name, tmp,
rec.backup_format)
ftp_server.storbinary('STOR %s' % backup_filename,
open(temp.name, "rb"))
@ -686,8 +689,7 @@ class DbBackupConfigure(models.Model):
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)
self.dump_data(rec.db_name, tmp, rec.backup_format)
try:
sftp.chdir(rec.sftp_path)
except IOError as e:
@ -723,7 +725,7 @@ class DbBackupConfigure(models.Model):
temp = tempfile.NamedTemporaryFile(
suffix='.%s' % rec.backup_format)
with open(temp.name, "wb+") as tmp:
odoo.service.db.dump_db(rec.db_name, tmp,
self.dump_data(rec.db_name, tmp,
rec.backup_format)
try:
headers = {
@ -784,7 +786,7 @@ class DbBackupConfigure(models.Model):
temp = tempfile.NamedTemporaryFile(
suffix='.%s' % rec.backup_format)
with open(temp.name, "wb+") as tmp:
odoo.service.db.dump_db(rec.db_name, tmp,
self.dump_data(rec.db_name, tmp,
rec.backup_format)
try:
dbx = dropbox.Dropbox(
@ -819,8 +821,7 @@ class DbBackupConfigure(models.Model):
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)
self.dump_data(rec.db_name, tmp, rec.backup_format)
headers = {
'Authorization': 'Bearer %s' % rec.onedrive_access_token,
'Content-Type': 'application/json'}
@ -880,8 +881,7 @@ class DbBackupConfigure(models.Model):
for item in nc.list(folder_path):
backup_file_name = item.path.split("/")[-1]
backup_date_str = \
backup_file_name.split("_")[
2]
backup_file_name.split("_")[2]
backup_date = fields.datetime.strptime(
backup_date_str, '%Y-%m-%d').date()
if (fields.date.today() - backup_date).days \
@ -915,7 +915,7 @@ class DbBackupConfigure(models.Model):
temp = tempfile.NamedTemporaryFile(
suffix='.%s' % rec.backup_format)
with open(temp.name, "wb+") as tmp:
odoo.service.db.dump_db(rec.db_name, tmp,
self.dump_data(rec.db_name, tmp,
rec.backup_format)
backup_file_path = temp.name
remote_file_path = f"/{folder_name}/{rec.db_name}_" \
@ -926,7 +926,7 @@ class DbBackupConfigure(models.Model):
temp = tempfile.NamedTemporaryFile(
suffix='.%s' % rec.backup_format)
with open(temp.name, "wb+") as tmp:
odoo.service.db.dump_db(rec.db_name, tmp,
self.dump_data(rec.db_name, tmp,
rec.backup_format)
backup_file_path = temp.name
remote_file_path = f"/{folder_name}/{rec.db_name}_" \
@ -986,7 +986,7 @@ class DbBackupConfigure(models.Model):
temp = tempfile.NamedTemporaryFile(
suffix='.%s' % rec.backup_format)
with open(temp.name, "wb+") as tmp:
odoo.service.db.dump_db(rec.db_name, tmp,
self.dump_data(rec.db_name, tmp,
rec.backup_format)
backup_file_path = temp.name
remote_file_path = f"{rec.aws_folder_name}/{rec.db_name}_" \
@ -1004,8 +1004,71 @@ class DbBackupConfigure(models.Model):
# field to the error message and log the error
rec.generated_exception = error
_logger.info('Amazon S3 Exception: %s', error)
# If notify_user is enabled, send an email to the user
# If notify_user is enabled, email the user
# notifying them about the failed backup
if rec.notify_user:
mail_template_failed.send_mail(rec.id,
force_send=True)
mail_template_failed.send_mail(rec.id, force_send=True)
def dump_data(self, db_name, stream, backup_format):
"""Dump database `db` into file-like object `stream` if stream is None
return a file object with the dump. """
cron_user_id = self.env.ref('auto_database_backup.ir_cron_auto_db_backup').user_id.id
if cron_user_id != self.env.user.id:
_logger.error(
'Unauthorized database operation. Backups should only be available from the cron job.')
raise ValidationError("Unauthorized database operation. Backups should only be available from the cron job.")
_logger.info('DUMP DB: %s format %s', db_name, backup_format)
cmd = [find_pg_tool('pg_dump'), '--no-owner', db_name]
env = exec_pg_environ()
if backup_format == 'zip':
with tempfile.TemporaryDirectory() as dump_dir:
filestore = odoo.tools.config.filestore(db_name)
cmd.append('--file=' + os.path.join(dump_dir, 'dump.sql'))
subprocess.run(cmd, env=env, stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT, check=True)
if os.path.exists(filestore):
shutil.copytree(filestore,
os.path.join(dump_dir, 'filestore'))
with open(os.path.join(dump_dir, 'manifest.json'), 'w') as fh:
db = odoo.sql_db.db_connect(db_name)
with db.cursor() as cr:
json.dump(self._dump_db_manifest(cr), fh, indent=4)
if stream:
odoo.tools.osutil.zip_dir(dump_dir, stream,
include_dir=False,
fnct_sort=lambda
file_name: file_name != 'dump.sql')
else:
t = tempfile.TemporaryFile()
odoo.tools.osutil.zip_dir(dump_dir, t, include_dir=False,
fnct_sort=lambda
file_name: file_name != 'dump.sql')
t.seek(0)
return t
else:
cmd.append('--format=c')
process = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE)
stdout, _ = process.communicate()
if stream:
stream.write(stdout)
else:
return stdout
def _dump_db_manifest(self, cr):
""" This function generates a manifest dictionary for database dump."""
pg_version = "%d.%d" % divmod(cr._obj.connection.server_version / 100, 100)
cr.execute(
"SELECT name, latest_version FROM ir_module_module WHERE state = 'installed'")
modules = dict(cr.fetchall())
manifest = {
'odoo_dump': '1',
'db_name': cr.dbname,
'version': odoo.release.version,
'version_info': odoo.release.version_info,
'major_version': odoo.release.major_version,
'pg_version': pg_version,
'modules': modules,
}
return manifest

35
auto_database_backup/static/description/index.html

@ -344,16 +344,13 @@
<span class="border-right-0"
style="float:right; margin-top:-4px; margin-right:-5px; width:5px; height:5px; border:1px solid #ddd; border-top:0; border-radius:0 0 0 5px"></span>
</li>
</ul>
</div>
<div class="col-md-12 tab-content ui-front"
style="border-top-right-radius:15px;border-bottom-right-radius:15px;height:auto;">
<div class="tab-pane fade active show" id="Screenshot" role="tabpanel" aria-labelledby="screenshot-1">
<div class="row" style="padding:4rem 2.5rem 0 !important; background-color:#fff !important">
<div class="col-lg-12 d-flex flex-column align-items-center">
<h1 class="text-center text-uppercase"
style="font-family:Montserrat, 'sans-serif' !important; font-size:40px !important; color:#791d97; font-weight:900 !important">
@ -443,7 +440,7 @@
new
Google API project and enabling the Google
Drive API, Go to the
<a href="https://console.developers.google.com/" target="_blank">Google API Console</a>
<a href="https://console.developers.google.com/">Google API Console</a>
and log into your
account.
While creating the project, for the
@ -952,21 +949,15 @@
class="col-lg-12 d-flex flex-column align-items-center">
</div>
</div>
</div>
</div>
<div class="tab-pane fade " id="Features" role="tabpanel" aria-labelledby="features-1">
<div class="tab-pane fade active show" id="Features" role="tabpanel" aria-labelledby="features-1">
<section class="oe_container pt16 mt16 pb-5">
<div class="row ">
<h3 style="color:#091E42; opacity:1; font-family:&quot;Montserrat&quot;; text-align:center; margin:auto; padding:25px; font-weight:600"
class="oe_slogan">
<!-- <span class="p-3"-->
<!-- style="color:#0074ff; font-weight:600">Comprehensive</span>Main-->
</h3>
<div class="col-lg-12 d-flex flex-column align-items-center">
<h1 class="text-center text-uppercase"
style="font-family:Montserrat, 'sans-serif' !important; font-size:40px !important; color:#791d97; font-weight:900 !important">
@ -979,10 +970,7 @@
Comprehensive Features of AUTOMATIC DATABASE
BACKUP</p>
</div>
<div class="row">
<div class="col-md-4 col-sm-6 mt48" style="padding-bottom: 10px">
<div class="bg-white shadow card"
style="border-radius:10px; padding:5px; height: 100%">
@ -1002,7 +990,6 @@
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 mt48" style="padding-bottom: 10px">
<div class="bg-white shadow card"
style="border-radius:10px; padding:5px; height: 100%">
@ -1023,7 +1010,6 @@
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 mt48" style="padding-bottom: 10px">
<div class="bg-white shadow card"
style="border-radius:10px; padding:5px; height: 100%">
@ -1043,7 +1029,6 @@
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 mt48" style="padding-bottom: 10px">
<div class="bg-white shadow card"
style="border-radius:10px; padding:5px; height: 100%">
@ -1111,10 +1096,9 @@
</div>
</div>
</section>
</div>
<div class="tab-pane fade " id="FAQS" role="tabpanel" aria-labelledby="faq-1">
<div class="tab-pane fade active show" id="FAQS" role="tabpanel" aria-labelledby="faq-1">
<div class="row" style="padding:4rem 2.5rem 0 !important; background-color:#fff !important">
<div class="col-lg-12 d-flex flex-column align-items-center">
@ -1233,11 +1217,8 @@
</div>
</div>
</div>
</div>
<div class="tab-pane fade " id="ReleaseNotes" role="tabpanel" aria-labelledby="video-1">
<div class="tab-pane fade active show" id="ReleaseNotes" role="tabpanel" aria-labelledby="video-1">
<div class="row" style="padding:4rem 2.5rem 0 !important; background-color:#fff !important">
<div class="col-lg-12 d-flex flex-column align-items-center">
<h1 class="text-center text-uppercase"
@ -1250,7 +1231,13 @@
<div class="tab-pane w-100">
<section class="oe_container mt48">
<div style="margin-bottom:4%">
<div class="relese-note w-100 pt-3 pb-2 pl-3 mb-4 pr-3 float-left"
style="border:1px solid #ccc; box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);">
<p><b> Version 17.0.3 I <span style="color:#3363c1; font-size: 14px;"> Updated
on : 18th April 2024</span></b>
</p>
<p> Fixed all the issues while inputting list_db = False. </p>
</div>
<div class="relese-note w-100 pt-3 pb-2 pl-3 mb-4 pr-3 float-left"
style="border:1px solid #ccc; box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);">
<p><b> Version 17.0.2 I <span style="color:#3363c1; font-size: 14px;"> Updated

Loading…
Cancel
Save