İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

Is there a way to backup databases through XMLRPC?

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
4 Cevaplar
8489 Görünümler
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
Vazgeç
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
En İyi Yanıt

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
Vazgeç
Avatar
Shashank Verma
En İyi Yanıt

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
Vazgeç
César Bustíos Benites
Üretici

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!

Üye Ol
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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