auto_backup icon indicating copy to clipboard operation
auto_backup copied to clipboard

Install auto_backup in an Odoo.sh Instance

Open MaxiMoogah opened this issue 4 years ago • 23 comments

Hello Yenthe,

I have used this module for on-premise databases and it works perfectly (Thank you for a great add-on). Now I was wanting to deploy this module in an Odoo.sh instance, specifically for the external server functionality, in order to be able to keep and use backups outside of Odoo.sh for different purposes.

Is it possible to use this module in Odoo.sh? If it is, could you help me out on how to configure it, since I haven't been able to get it to work. It returns a "Connection refused" error message.

Thank you very much and best regards

MaxiMoogah avatar Apr 15 '20 19:04 MaxiMoogah

Hi,

Actually this should work out of the box. This is exactly what the requirements.txt file does since SH automatically installs these packages. It should work fine for V11/V12/V13. You could connect to the terminal of the SH instance and check if the package is indeed installed on the instance. Are you sure that your external credentials are valid though?

Yenthe666 avatar Apr 16 '20 14:04 Yenthe666

Hello Yenthe,

first of all, thank you for the answer. The dependency is installed, and didn't have an issue during the build. I am using it for V10. Will try it with a newer Odoo version to see if the issue persists.

But I think the issue is with Odoo.SH. Its not about the external server. It doesn't even find the database its supposed to backup. Maybe Odoo.SH doesn't have db.backup model available to be executed within the instance? Or it might be that the /web/database/manager is not accesible?

Im attaching a screenshot of the error pop-up just in case.

Thanks again Screen Shot 2020-04-16 at 11 49 50 AM

MaxiMoogah avatar Apr 16 '20 14:04 MaxiMoogah

Hmm, that might be the case because the database manager is disabled actually.. You can't access it in SH, right? I only have a solution for this since V13 where I no longer rely on the database manager. You could backport this to 10.0 I guess. See https://github.com/Yenthe666/auto_backup/commit/c7d0512a0d0b2d42662831008e7a9316b264f23e

Yenthe666 avatar Apr 16 '20 16:04 Yenthe666

Replaced the whole db_backup.py file in the V10 add-on and worked like a charm!

Thanks a million.

MaxiMoogah avatar Apr 16 '20 20:04 MaxiMoogah

My bad, doesn't work like a charm, jaja. It lets me save the config, generates a file in the backup directory and it transfers it. The only problem is that it generates an empty file.

I'll look into it a little more and let you know. Thanks for the help.

MaxiMoogah avatar Apr 16 '20 20:04 MaxiMoogah

Hmm.. debugging on SH is a bit annoying. You could add log statements and get them printed to see if you notice anything odd

Yenthe666 avatar Apr 17 '20 06:04 Yenthe666

Hi, having the same issue. Does your module uses the API for backup? DB manager is completely disabled in SH. Backup and restore must be made with the SH GUI.

I think SH does not allow backups using API. The API is to work with the database (maybe only CRUD?). In psql, I can´t even list the tables (I get an access denied).

Here is part of the documentation: https://www.odoo.sh/faq

Is there an API for Odoo.sh?

Yes, there is an API to interact with your Odoo databases hosted on Odoo.sh.

Each Odoo build comes with an XML-RPC interface. It allows you to interact from an external application. You can find here the documentation for the Odoo API.

In order to connect to your database, you will need:

the database URL (eg: mydatabase.dev.odoo.com)
the port number is 443
the database name can be found in the shell by typing psql and checking the prompt invite name (the part before the =>)
the login and password for the desired user

Platform API

If you are looking for an API to interact with the Odoo.sh platform (eg: creating a new project, new branches or requesting a rebuild), this is not planned to be developed for now.

I suppose this includes backups. Here is the error log in SH trying to make a backup:

Error: Odoo Server Error

Traceback (most recent call last): File "/home/odoo/src/odoo/odoo/tools/safe_eval.py", line 349, in safe_eval return unsafe_eval(c, globals_dict, locals_dict) File "", line 1, in File "/home/odoo/src/user/auto_backup/models/db_backup.py", line 124, in schedule_backup os.makedirs(rec.folder) File "/usr/lib/python3.6/os.py", line 210, in makedirs makedirs(head, mode, exist_ok) File "/usr/lib/python3.6/os.py", line 220, in makedirs mkdir(name, mode) OSError: [Errno 30] Read-only file system: '/odoo'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/odoo/src/odoo/odoo/http.py", line 624, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/odoo/src/odoo/odoo/http.py", line 310, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/home/odoo/src/odoo/odoo/tools/pycompat.py", line 14, in reraise raise value File "/home/odoo/src/odoo/odoo/http.py", line 669, in dispatch result = self._call_function(**self.params) File "/home/odoo/src/odoo/odoo/http.py", line 350, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/odoo/src/odoo/odoo/service/model.py", line 94, in wrapper return f(dbname, *args, **kwargs) File "/home/odoo/src/odoo/odoo/http.py", line 339, in checked_call result = self.endpoint(*a, **kw) File "/home/odoo/src/odoo/odoo/http.py", line 915, in call return self.method(*args, **kw) File "/home/odoo/src/odoo/odoo/http.py", line 515, in response_wrap response = f(*args, **kw) File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1326, in call_button action = self._call_kw(model, method, args, kwargs) File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1314, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/home/odoo/src/odoo/odoo/api.py", line 387, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/home/odoo/src/odoo/odoo/api.py", line 374, in _call_kw_multi result = method(recs, *args, **kwargs) File "/home/odoo/src/odoo/odoo/addons/base/models/ir_cron.py", line 76, in method_direct_trigger self.with_user(cron.user_id).ir_actions_server_id.run() File "/home/odoo/src/odoo/odoo/addons/base/models/ir_actions.py", line 545, in run res = func(action, eval_context=eval_context) File "/home/odoo/src/odoo/odoo/addons/base/models/ir_actions.py", line 430, in run_action_code_multi safe_eval(action.sudo().code.strip(), eval_context, mode="exec", nocopy=True) # nocopy allows to return 'action' File "/home/odoo/src/odoo/odoo/tools/safe_eval.py", line 372, in safe_eval pycompat.reraise(ValueError, ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr)), exc_info[2]) File "/home/odoo/src/odoo/odoo/tools/pycompat.py", line 13, in reraise raise value.with_traceback(tb) File "/home/odoo/src/odoo/odoo/tools/safe_eval.py", line 349, in safe_eval return unsafe_eval(c, globals_dict, locals_dict) File "", line 1, in File "/home/odoo/src/user/auto_backup/models/db_backup.py", line 124, in schedule_backup os.makedirs(rec.folder) File "/usr/lib/python3.6/os.py", line 210, in makedirs makedirs(head, mode, exist_ok) File "/usr/lib/python3.6/os.py", line 220, in makedirs mkdir(name, mode) ValueError: <class 'OSError'>: "30 Read-only file system" while evaluating 'model.schedule_backup()'

Kapitan2015 avatar May 15 '20 23:05 Kapitan2015

@Kapitan2015 in V13 I've made changes a while ago that allow taking a backup without needing the database manager enabled. See https://github.com/Yenthe666/auto_backup/commit/c7d0512a0d0b2d42662831008e7a9316b264f23e

Yenthe666 avatar May 16 '20 08:05 Yenthe666

Thanks for the reply @Yenthe666 . The logs I put on my previous comment are on odoo.sh v13 EE. I tried multiple file locations (usr, tmp, var, odoo, etc.) and get a file with size 0. Maybe there I can post the log or anything that can give lights on the issue?

Kapitan2015 avatar May 16 '20 23:05 Kapitan2015

Looks like the folder doesn't have enough rights honestly (ValueError: <class 'OSError'>: "30 Read-only file system" while evaluating) which is causing the 0 bytes.

Yenthe666 avatar May 18 '20 07:05 Yenthe666

Yes, seems so. I tried giving it permissions but got the same error. Maybe something in Odoo.sh is preventing the job to write. I even made a fresh folder and got the same result.

Kapitan2015 avatar May 18 '20 22:05 Kapitan2015

I also get empty files in odoo.sh, writing in /tmp/odoo/backups. So I created an ir.cron with this code:

io = model.get_io()  # I added a method to get the io module
fp = io.BytesIO()
datas = model._take_dump(model._cr.dbname, fp, "", "zip")

And I got this error:

  File "/home/odoo/src/user/auto_backup/auto_backup/models/db_backup.py", line 297, in _take_dump
    odoo.tools.exec_pg_command(*cmd)
  File "/home/odoo/src/odoo/odoo/tools/misc.py", line 132, in exec_pg_command
    raise Exception('Postgres subprocess %s error %s' % (args2, rc))
ValueError: <class 'Exception'>: "Postgres subprocess ('/usr/bin/pg_dump', '--no-owner', '--file=/tmp/tmpjdrprnsj/dump.sql', 'mydatabasename') error 1" while evaluating
'io = model.get_io()\n\nfp = io.BytesIO()\ndatas = model._take_dump(model._cr.dbname, fp, "", "zip")'

complete traceback here: https://pastebin.com/0AirAwUJ

Linekio avatar Jun 15 '20 18:06 Linekio

@Linekio Did you manage to make a backup?

Kapitan2015 avatar Aug 15 '20 16:08 Kapitan2015

No, I asked for better access rights and I use the odoo.sh backup system.

Marcodewame avatar Aug 15 '20 16:08 Marcodewame

Thanks @Marcodewame. Maybe a workaround could be an RPA that triggers daily.

Kapitan2015 avatar Aug 15 '20 16:08 Kapitan2015

I also have the same problem of a dump of 0ko under Odoo.sh V13 Has anyone managed to get the module to work on Odoo.sh? In which directory should the dump be generated?

Barronjj avatar Jan 18 '21 21:01 Barronjj

I have yet to find a solution for this honestly. The psql is shielded off differently then an on premise installation sadly.

Yenthe666 avatar Jan 18 '21 21:01 Yenthe666

I have the same problem with odoo.sh and another backup module I installed before I found yours. The problem is with not enough rights for the database user to execute pg_dump. pg_dump pg_dump: [archiver (db)] query failed: ERROR: permission denied for relation pg_roles I don't think this is solvable without elevating the rights of the db user in odoo.sh. I posted a ticket to odoo.sh support, but I'm pessimistic about the response. Will keep you informed.

dymitar avatar Feb 01 '21 18:02 dymitar

Awesome, thanks :)

Yenthe666 avatar Feb 02 '21 06:02 Yenthe666

I have an answer from odoo.sh support. Here is part of it:

"...This module is not compatible with Odoo.sh. This is due to the fact that it is not possible to remotely connect to a postgresql Odoo.sh database. The Odoo hosting platforms (Odoo Online and Odoo.sh) do not expose the postgresql clusters to the internet. However, there are other ways in which is possible to automatize backups. In fact, from the shell of the instance, you can have access to the latest backup. It is situated at /home/odoo/backup.daily. You will need to then copy it through ssh in a customized script. However, this feature includes only the latest backup, so you won't have a way to synchronise all the older dumps in an automated fashion...."

In the daily backup there is a database dump with name <database_name>_daily.sql.gz. Probably the functionality of the module can be adjusted with a parameter (checkbox) "odoo.sh installation". In this case it should not try to backup the database, but to take the daily backup. Of course in this case there should be an explanation that this is the daily backup, not a backup, created at the moment of execution. I hope this can help you.

dymitar avatar Feb 08 '21 12:02 dymitar

Thanks for the information, it clarifies alot. Did they mentioned if its possible to automate the Staging backups? Currently there is no daily backup and needs to be manually created.

Kapitan2015 avatar Feb 08 '21 15:02 Kapitan2015

Hmm interesting. So TLDR is impossible without making some hook for SH specifically which is just once a day..

Yenthe666 avatar Feb 08 '21 16:02 Yenthe666

Staging backups is not possible to automate. But I'm not very concerned about staging :-) Production is important for me, because I think relying only on odoo.sh for everything is not a good strategy. I think usually one would configure the auto_backup to be once a day, and taking the already created db dump is a good option.

dymitar avatar Feb 08 '21 18:02 dymitar

I've just been in contact with ODOO support trying to push this issue forward. Currently there are two issues on odoo.sh preventing this to work.

  1. pg_dump and DB version discrepancy (pg_dump is 12, DB is 14)
  2. pg_dump reports this error:
pg_dump: error: query failed: ERROR:  permission denied for view pg_roles

I managed to bypass the first issue by uploading a newer binary. The second I guess can't be bypassed (unless I wrote my pg_dump). In brief, the response to this error was:

The technical team couldn't tell me when it would be possible to proceed as you described in your previous message.

So it looks like they don't have any timeline at the moment for solving this issue.

edisuc avatar Feb 09 '23 13:02 edisuc

I've been thinking about another solution actually. Odoo does a backup daily and stores the last one on the disk, so if we could just 'search'/forward it to the other system through the SFTP layer it should work with the limitation that you cannot control when the backup is taken and that you can only grab/write the last one.

Yenthe666 avatar Feb 10 '23 09:02 Yenthe666

I'm planning to do exactly this for my client (in a month or two). If you are ok with this, we could do it on your code and share back, so you can make it public.

edisuc avatar Feb 10 '23 10:02 edisuc

Yes :) I think that maybe it is best to add it as a second app with a dependency on auto_backup which then adds the behaviour/logic. We have somebody that is interested too so whenever one of us wants to start it let us touch base so we do not waste resources/time

Yenthe666 avatar Feb 10 '23 10:02 Yenthe666

Great. I agree.

edisuc avatar Feb 10 '23 10:02 edisuc

We started working on this enhancement. The plan is to create a new module auto_backup_odoosh which will enhance auto_backup. It will add and option to choose between classical odoo server configuration (server, port, database...) and odoo.sh. If the later will be chosen, a new function will generate the odoo backup file from the dump odoo.sh regularly creates. After this, auto_backup will copy the file to the remote location.

This is the general idea. Will let you know more in a few days.

edisuc avatar Apr 13 '23 15:04 edisuc

@edisuc heyhey! Do you have an update here? :)

Yenthe666 avatar May 01 '23 13:05 Yenthe666