While restoring database ,its contents are stored in binary format.
I tested a script and works fine.
U just need to do a little code alteration in ur openerp file.
Note: Tested for OpenERP 7.0
STEP 1:
Find and open web_services.py in your openerp directory. I found this on /openerp/service/web_services.py
STEP 2:
Find function -
def exp_dump(self, db_name):
And replace this entire function with -
def exp_dump(self, db_name):
logger = logging.getLogger('openerp.service.web_services.db.dump')
with self._set_pg_password_in_environment():
cmd = ['pg_dump', '--format=c', '--no-owner']
if tools.config['db_user']:
cmd.append('--username=' + tools.config['db_user'])
if tools.config['db_host']:
cmd.append('--host=' + tools.config['db_host'])
if tools.config['db_port']:
cmd.append('--port=' + str(tools.config['db_port']))
cmd.append(db_name)
stdin, stdout = tools.exec_pg_command_pipe(*tuple(cmd))
stdin.close()
data = stdout.read()
res = stdout.close()
#store data
with open(os.getcwd()+'/data1.txt','w') as w:
w.write(data)
if not data or res:
logger.error(
'DUMP DB: %s failed! Please verify the configuration of the database password on the server. '
'You may need to create a .pgpass file for authentication, or specify `db_password` in the '
'server configuration file.\n %s', db_name, data)
raise Exception, "Couldn't dump database"
logger.info('DUMP DB successful: %s', db_name)
return base64.encodestring(data)
#NOTE: with open(os.getcwd()+'/data1.txt','w') as w: #This line store a dump file in binary format on ur current directory
#Kindly remember the directory path ,useful when restoring the dump file
STEP 3:
FInd function -
def exp_restore(self, db_name, data):
Replace this fucntion by -
def exp_restore(self, db_name, data):
logger = logging.getLogger('openerp.service.web_services.db.restore')
try:
with open(data,'r') as w:
data=w.read()
except Exception as E:
pass
with self._set_pg_password_in_environment():
if self.exp_db_exist(db_name):
logger.warning('RESTORE DB: %s already exists', db_name)
raise Exception, "Database already exists"
self._create_empty_database(db_name)
cmd = ['pg_restore', '--no-owner']
if tools.config['db_user']:
cmd.append('--username=' + tools.config['db_user'])
if tools.config['db_host']:
cmd.append('--host=' + tools.config['db_host'])
if tools.config['db_port']:
cmd.append('--port=' + str(tools.config['db_port']))
cmd.append('--dbname=' + db_name)
args2 = tuple(cmd)
buf=base64.decodestring(data)
if os.name == "nt":
tmpfile = (os.environ['TMP'] or 'C:\\') + os.tmpnam()
file(tmpfile, 'wb').write(buf)
args2=list(args2)
args2.append(tmpfile)
args2=tuple(args2)
stdin, stdout = tools.exec_pg_command_pipe(*args2)
if not os.name == "nt":
stdin.write(base64.decodestring(data))
stdin.close()
res = stdout.close()
if res:
raise Exception, "Couldn't restore database"
logger.info('RESTORE DB: %s', db_name)
return True
#NOTE: try: # This code reads & restor the dump file path which u provide in ur xmlrpc script
with open(data,'r') as w:
data=w.read()
except Exception as E:
pass
STEP 4:
Your xmlrpc script-
import xmlrpclib,os
sock_comm = xmlrpclib.ServerProxy('http://urdomain/xmlrpc/db')
#NOTE: In case if your are taking backup
sock_comm.dump(your_super_user_password,database_name) #Example -dump('admin','test_db')
#NOTE:In case if your restoring dump file
sock_comm.restore(your_super_user_password,new_database_name,your_dump_file_path_on_disk) #Example -restore('admin','test_db','/user/erp/my_file.txt)
THATS IT !!!!
While managing database you do not require to use login method like uid = sock.login('mydb', 'myuser', 'mypass') dump method accepts 2arguements example .dump(super_user_password,urdatbase_name)