auto_backup
auto_backup copied to clipboard
Install auto_backup in an Odoo.sh Instance
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
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?
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
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
Replaced the whole db_backup.py file in the V10 add-on and worked like a charm!
Thanks a million.
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.
Hmm.. debugging on SH is a bit annoying. You could add log statements and get them printed to see if you notice anything odd
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
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
@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
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?
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.
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.
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 Did you manage to make a backup?
No, I asked for better access rights and I use the odoo.sh backup system.
Thanks @Marcodewame. Maybe a workaround could be an RPA that triggers daily.
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?
I have yet to find a solution for this honestly. The psql is shielded off differently then an on premise installation sadly.
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.
Awesome, thanks :)
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.
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.
Hmm interesting. So TLDR is impossible without making some hook for SH specifically which is just once a day..
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.
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.
- pg_dump and DB version discrepancy (pg_dump is 12, DB is 14)
- 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.
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.
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.
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
Great. I agree.
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 heyhey! Do you have an update here? :)