Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Is there a way to backup databases through XMLRPC?

Odoberať

Get notified when there's activity on this post

This question has been flagged
4 Replies
8488 Zobrazenia
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
Zrušiť
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
Zrušiť
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
Zrušiť
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!

Registrácia
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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