Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Is there a way to backup databases through XMLRPC?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
4 Respostes
8478 Vistes
Avatar
César Bustíos Benites

I'm trying to generate a Python script to backup my database:

import xmlrpclib

sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')

uid = sock.login('mydb', 'myuser', 'mypass')

sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/db')

sock.dump('mydb')

Traceback (most recent call last)

....

Fault: <Fault AccessDenied: 'Access denied.'>

Is this possible?

I'm currently using the scripts dump_db.sh and housekeeping.sh as shown in this question: https://www.odoo.com/forum/help-1/question/how-to-setup-a-regular-postgresql-database-backup-4728 but I can't find a way to restore the database.

Thanks!

0
Avatar
Descartar
Shashank Verma

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)

Avatar
Anil Kesariya
Best Answer

César Bustíos Benites,

Here is one more best example to take multiple database backup.

import base64

import xmlrpclib

sock = xmlrpclib.ServerProxy('http://192.168.1.12:8069/xmlrpc/db') #provide IP address of your customer server where all database are running

all_database = sock.list()

for database in all_database:

file_path = "/home/serpentcs/backup/" #Give path of folder where backup file will be store

file_path += database

file_path += ".dump"

backup_db_file = open(file_path, 'wb')

backup_db_file.write(base64.b64decode(sock.dump('admin', database))) #admin is master password in my case

backup_db_file.close()

Hope this will help.

Rgds,

Anil.


2
Avatar
Descartar
Avatar
Shashank Verma
Best Answer

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 !!!!

 

 

1
Avatar
Descartar
César Bustíos Benites
Autor

Thank you very much! I'll accept yours answer although, as you mentioned in your comments, it's only required to use "dump(super_user_pass, db_name)"

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now