67 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
			
		
		
	
	
			67 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
| # Copyright 2018-Today datenpol gmbh(<http://www.datenpol.at>)
 | |
| # License OPL-1 or later (https://www.odoo.com/documentation/user/11.0/legal/licenses/licenses.html#licenses).
 | |
| 
 | |
| import datetime
 | |
| import json
 | |
| import logging
 | |
| import os
 | |
| import sys
 | |
| 
 | |
| import jinja2
 | |
| import werkzeug
 | |
| from odoo.addons.web.controllers.main import DBNAME_PATTERN, db_monodb, Database
 | |
| 
 | |
| import odoo
 | |
| from odoo import http
 | |
| from odoo.http import content_disposition
 | |
| 
 | |
| _logger = logging.getLogger(__name__)
 | |
| 
 | |
| if hasattr(sys, 'frozen'):
 | |
|     # When running on compiled windows binary, we don't have access to package loader.
 | |
|     path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'views'))
 | |
|     loader = jinja2.FileSystemLoader(path)
 | |
| else:
 | |
|     loader = jinja2.PackageLoader('odoo.addons.dp_dump_anonym', "views")
 | |
| 
 | |
| env = jinja2.Environment(loader=loader, autoescape=True)
 | |
| env.filters["json"] = json.dumps
 | |
| 
 | |
| 
 | |
| class DatabaseExtended(Database):
 | |
|     def _render_template(self, **d):
 | |
|         d.setdefault('manage', True)
 | |
|         d['insecure'] = odoo.tools.config.verify_admin_password('admin')
 | |
|         d['list_db'] = odoo.tools.config['list_db']
 | |
|         d['langs'] = odoo.service.db.exp_list_lang()
 | |
|         d['countries'] = odoo.service.db.exp_list_countries()
 | |
|         d['pattern'] = DBNAME_PATTERN
 | |
|         # databases list
 | |
|         d['databases'] = []
 | |
|         try:
 | |
|             d['databases'] = http.db_list()
 | |
|             d['incompatible_databases'] = odoo.service.db.list_db_incompatible(d['databases'])
 | |
|         except odoo.exceptions.AccessDenied:
 | |
|             monodb = db_monodb()
 | |
|             if monodb:
 | |
|                 d['databases'] = [monodb]
 | |
|         return env.get_template("database_manager.html").render(d)
 | |
| 
 | |
|     @http.route('/web/database/backup', type='http', auth="none", methods=['POST'], csrf=False)
 | |
|     def backup(self, master_pwd, name, backup_format='zip', raw=False):
 | |
|         try:
 | |
|             odoo.service.db.check_super(master_pwd)
 | |
|             ts = datetime.datetime.utcnow().strftime("%Y-%m-%d_%H-%M-%S")
 | |
|             filename = "%s_%s.%s" % (name, ts, backup_format)
 | |
|             headers = [
 | |
|                 ('Content-Type', 'application/octet-stream; charset=binary'),
 | |
|                 ('Content-Disposition', content_disposition(filename)),
 | |
|             ]
 | |
|             dump_stream = odoo.service.db.dump_db(name, None, backup_format, raw)
 | |
|             response = werkzeug.wrappers.Response(dump_stream, headers=headers, direct_passthrough=True)
 | |
|             return response
 | |
|         except Exception as e:
 | |
|             _logger.exception('Database.backup')
 | |
|             error = "Database backup error: %s" % (str(e) or repr(e))
 | |
|             return self._render_template(error=error)
 |