Backup Odoo db from within odoo

后端 未结 8 958
北恋
北恋 2021-01-11 14:22

I need to backup the current db while logged into odoo. I should be able to do it using a button, so that suppose I click on the button, it works the same way as odoo defaul

8条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-11 15:16

    Add a button somewhere and call a controller like this one.

    @http.route('/backup/download', auth="user", type='http')
            def backup(self, **kw):
                ts = datetime.datetime.utcnow().strftime("%Y-%m-%d_%H-%M-%S")
                filename = "%s_%s.zip" % (request.env.cr.dbname, ts)
                headers = [
                    ('Content-Type', 'application/octet-stream; charset=binary'),
                    ('Content-Disposition', content_disposition(filename)),
                ]
                dump_stream = db.dump_db(request.env.cr.dbname, None)
                response = werkzeug.wrappers.Response(dump_stream, headers=headers, direct_passthrough=True)
                return response
    

提交回复
热议问题