Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

odoo backup and restore through xmlrpc

By
joachim grubelnik
on 9/9/15, 1:02 PM 1,042 views

i did a backup with db.py help 

# Backup DB
# service/db.py: def exp_dump(db_name):
def backup(args):
with open(args.filedump, 'w') as f:
f.write(server.dump(args.superpwd, args.database).decode('base64'))
if f:
print 'Database Backup File Name: %s' % f.name
sys.exit(0)
else:
sys.exit(2)

This Works great, the zip file created works in the gui at restore perfectly, now i want to write another script to use the restore function, but i am getting an error 

used this

# Restore DB
# service/db.py: def exp_restore(db_name, data, copy=False):
def restore(args):
print 'Restore Database: %s' % args.database
if server.restore(args.superpwd, args.database, args.filedump):
sys.exit(0)
else:
sys.exit(2)

this raises the error of the following, anyone a short IDEA of what the problem could be?

Traceback (most recent call last):
  File "/opt/odoo_v8.0/TOOLS/db-tools.py", line 108, in <module>
    args.func(args)
  File "/opt/odoo_v8.0/TOOLS/db-tools.py", line 57, in restore
    if server.restore(args.superpwd, args.database, args.filedump):
  File "/usr/lib/python2.7/xmlrpclib.py", line 1233, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1587, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1273, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1306, in single_request
    return self.parse_response(response)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1482, in parse_response
    return u.close()
  File "/usr/lib/python2.7/xmlrpclib.py", line 794, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault Incorrect padding: 'Traceback (most recent call last):\n  File "/opt/odoo_v8.0/odoo/openerp/service/wsgi_server.py", line 75, in xmlrpc_return\n    result = openerp.http.dispatch_rpc(service, method, params)\n  File "/opt/odoo_v8.0/odoo/openerp/http.py", line 115, in dispatch_rpc\n    result = dispatch(method, params)\n  File "/opt/odoo_v8.0/odoo/openerp/service/db.py", line 73, in dispatch\n    return fn(*params)\n  File "/opt/odoo_v8.0/odoo/openerp/service/db.py", line 215, in exp_restore\n    data_file.write(data.decode(\'base64\'))\n  File "/usr/lib/python2.7/encodings/base64_codec.py", line 42, in base64_decode\n    output = base64.decodestring(input)\n  File "/usr/lib/python2.7/base64.py", line 321, in decodestring\n    return binascii.a2b_base64(s)\nError: Incorrect padding\n'>Traceback (most recent call last):
File "/opt/odoo_v8.0/TOOLS/db-tools.py", line 108, in <module>
args.func(args)
File "/opt/odoo_v8.0/TOOLS/db-tools.py", line 57, in restore
if server.restore(args.superpwd, args.database, args.filedump):
File "/usr/lib/python2.7/xmlrpclib.py", line 1233, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1587, in __request
verbose=self.__verbose
File "/usr/lib/python2.7/xmlrpclib.py", line 1273, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python2.7/xmlrpclib.py", line 1306, in single_request
return self.parse_response(response)
File "/usr/lib/python2.7/xmlrpclib.py", line 1482, in parse_response
return u.close()
File "/usr/lib/python2.7/xmlrpclib.py", line 794, in close
raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault Incorrect padding: 'Traceback (most recent call last):\n File "/opt/odoo_v8.0/odoo/openerp/service/wsgi_server.py", line 75, in xmlrpc_return\n result = openerp.http.dispatch_rpc(service, method, params)\n File "/opt/odoo_v8.0/odoo/openerp/http.py", line 115, in dispatch_rpc\n result = dispatch(method, params)\n File "/opt/odoo_v8.0/odoo/openerp/service/db.py", line 73, in dispatch\n return fn(*params)\n File "/opt/odoo_v8.0/odoo/openerp/service/db.py", line 215, in exp_restore\n data_file.write(data.decode(\'base64\'))\n File "/usr/lib/python2.7/encodings/base64_codec.py", line 42, in base64_decode\n output = base64.decodestring(input)\n File "/usr/lib/python2.7/base64.py", line 321, in decodestring\n return binascii.a2b_base64(s)\nError: Incorrect padding\n'>

Thanks in Advance cheers 

2

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 9/9/15, 9:58 PM

You need to encode again to base64, because Odoo is trying to decode it

right now i am doing the whole restore like it is done from "eqms" Thanks to Martin for this see this for detail https://github.com/equitania/odoo-addons/blob/8.0/scripts/restore-zip.sh

joachim grubelnik
on 9/18/15, 9:09 AM
0
joachim grubelnik
On 9/10/15, 4:19 AM

Perfect thanks i just added the encode and works fine now

def restore(args):
print 'Restore Database: %s' % args.database
if server.restore(args.superpwd, args.database, (args.filedump).encode('base64')):
sys.exit(0)
else:
sys.exit(2)
but raising another error message now, even the restore has been done and the database is restored, any idea ? 
Traceback (most recent call last):
File "/opt/odoo_v8.0/TOOLS/db-tools.py", line 114, in <module>
args.func(args)
File "/opt/odoo_v8.0/TOOLS/db-tools.py", line 49, in restore
if server.restore(args.superpwd, args.database, (args.filedump).encode('base64')):
File "/usr/lib/python2.7/xmlrpclib.py", line 1233, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1587, in __request
verbose=self.__verbose
File "/usr/lib/python2.7/xmlrpclib.py", line 1273, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python2.7/xmlrpclib.py", line 1306, in single_request
return self.parse_response(response)
File "/usr/lib/python2.7/xmlrpclib.py", line 1482, in parse_response
return u.close()
File "/usr/lib/python2.7/xmlrpclib.py", line 794, in close
raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault Postgres subprocess ('/usr/bin/pg_restore', '--username=o8_autoupdatetools2', '--host=127.0.0.1', '--dbname=o8_autoupdatetools2', '--no-owner', '/tmp/tmphlEcTF') error 1: 'Traceback (most recent call last):\n File "/opt/odoo_v8.0/odoo/openerp/service/wsgi_server.py", line 75, in xmlrpc_return\n result = openerp.http.dispatch_rpc(service, method, params)\n File "/opt/odoo_v8.0//odoo/openerp/http.py", line 115, in dispatch_rpc\n result = dispatch(method, params)\n File "/opt/odoo_v8.0/odoo/openerp/service/db.py", line 73, in dispatch\n return fn(*params)\n File "/opt/odoo_v8.0/odoo/openerp/service/db.py", line 217, in exp_restore\n restore_db(db_name, data_file.name, copy=copy)\n File "/opt/odoo_v8.0/odoo/openerp/service/db.py", line 260, in restore_db\n if openerp.tools.exec_pg_command(pg_cmd, *pg_args):\n File "/opt/odoo_v8.0/odoo/openerp/tools/misc.py", line 128, in exec_pg_command\n raise Exception(\'Postgres subprocess %s error %s\' % (args2, rc))\nException: Postgres subprocess (\'/usr/bin/pg_restore\', \'--username=o8_autoupdatetools2\', \'--host=127.0.0.1\', \'--dbname=o8_autoupdatetools2\', \'--no-owner\', \'/tmp/tmphlEcTF\') error 1\n'>
DEBUG: args: Namespace(baseport='10369', database='o8_autoupdatetools2', filedump='/opt/odoo_v8.0/o8_autoupdatetools2/BACKUP/o8_autoupdatetools2.zip', func=<function restore at 0x7fe6dd953230>, superpwd='xxxxx') server: <ServerProxy for localhost:10369/xmlrpc/db> Restore Database: o8_autoupdatetools2

That error didn't tell me anything, check PostgresSQL logs for more or try to manually run the generated command "/usr/bin/pg_restore --username=o8_autoupdatetools2 --host=127.0.0.1 --dbname=o8_autoupdatetools2 --no-owner /tmp/tmphlEcTF". Replace "/tmp/tmphlEcTF" with a file containing the dump and see what error could be happening, create a new bd for that and also replace it in the command before

Axel Mendoza
on 9/10/15, 4:36 AM

when i do a creation like this ${INSTANCE_PATH}/TOOLS/db-tools.py -b ${BASEPORT69} -s ${SUPER_PASSWORD} newdb -d ${DBNAME} -p 'xxxx' works great, when i after this do the restore it correctly tells me database exists. When i do not create it i get the error above xmlrpclib.Fault:

joachim grubelnik
on 9/10/15, 8:47 AM

I think that you need to first create the db, then next do a restore on it, it's mandatory that the database need to exist

Axel Mendoza
on 9/12/15, 2:58 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 9/9/15, 1:02 PM
Seen: 1042 times
Last updated: 9/10/15, 4:19 AM