Technical mailing list archives


Re: Database Restore Error

Métal Sartigan, Jérôme Thériault
- 12/14/17 14:06:33
The goal is to completely bypass Odoo and manually restore your files directly to the file system, and to the postgres database. Here is the relevant part of odoo code that does that. If you can understand python, everything you need to know is in there. The procedure should be the same accross odoo version, at least since 8.0.

def restore_db(db, dump_file, copy=False):
    assert isinstance(db, pycompat.string_types)
    if exp_db_exist(db):'RESTORE DB: %s already exists', db)
        raise Exception("Database already exists")


    filestore_path = None
    with as dump_dir:
        if zipfile.is_zipfile(dump_file):
            # v8 format
            with zipfile.ZipFile(dump_file, 'r') as z:
                # only extract known members!
                filestore = [m for m in z.namelist() if m.startswith('filestore/')]
                z.extractall(dump_dir, ['dump.sql'] + filestore)

                if filestore:
                    filestore_path = os.path.join(dump_dir, 'filestore')

            pg_cmd = 'psql'
            pg_args = ['-q', '-f', os.path.join(dump_dir, 'dump.sql')]

            # <= 7.0 format (raw pg_dump output)
            pg_cmd = 'pg_restore'
            pg_args = ['--no-owner', dump_file]

        args = []
        args.append('--dbname=' + db)
        pg_args = args + pg_args

        if, *pg_args):
            raise Exception("Couldn't restore database")

        registry =
        with registry.cursor() as cr:
            env = odoo.api.Environment(cr, SUPERUSER_ID, {})
            if copy:
                # if it's a copy of a database, force generation of a new dbuuid
            if filestore_path:
                filestore_dest = env['ir.attachment']._filestore()
                shutil.move(filestore_path, filestore_dest)

                    with cr.savepoint():
                        cr.execute("CREATE EXTENSION unaccent")
                except psycopg2.Error:

Le jeu. 14 déc. 2017 à 13:10, Can Tecim <> a écrit :
db dump file contains the attachments, odoo uses ir.attachment model to record file metadata like name, file path on the disk etc. so it stores the file in the storage. Restoring the database is not enough, you should restore filestore folder too. zip file should contain a folder called filestore iirc could you check that?

2017-12-14 20:55 GMT+03:00 Arlosyst <>:
So, it will restore all the images and be a proper restore. right?
On Thu, Dec 14, 2017 at 11:20 PM, Can Tecim <> wrote:
It contains a dump file created with pg_dump

so you can use psql command line tool "psql -q -h ${DATABASE_HOST} -U ${USER_NAME} -d ${DATABASE} -f dump.sql"
2017-12-14 20:45 GMT+03:00 Arlosyst <>:
How do we restore ZIP backup via postgres?
On Thu, Dec 14, 2017 at 10:20 PM, Xavier Brochard <> wrote:
Le jeudi 14 décembre 2017, 13:00:13 CET Arlosyst a écrit :
> Hi All, > I am trying to restore DB of size 1.25 GB to Odoo server. However, I am > getting error "Database restore error: MemoryError()" when i am trying to > do so. Has anyone faced similar issue/ > Thanks & Regards, Arlosyst
If you don't want to patch as suggested by Jérome, you may try to restore the db directly on server. I suggest to use lynx text browser for that. First you should increase nginx limit ; add this in your nginx.conf : # increase size to restoring backups client_max_body_size 1300M; Note also that your backup file contains probably the filestore datas and the postgresql dump. You need only the dump to restore the DB. The filestore datas can be directly copied to the server disk (at the right place!). Hope this help Xavier


Post to:

Best Regards,,
Can Tecim, CTO
Projet Grup


Post to:

Best Regards,,
Can Tecim - Projet Grup

Post to:


Analyste-programmeur, système Odoo

418-228-1851 #248 | 1-888-865-2284
1000, 40e Rue Ouest, St-Georges (Québec) G5Y 6V2

Cet envoi transmis par courriel est confidentiel et peut contenir de l’information privilégiée qui est protégée par le secret professionnel. Il est à l'usage exclusif du destinataire ci-dessus. Toute autre personne que le destinataire ou l’agent responsable de la livraison du message au destinataire véritable est par la présente avisée qu'il est strictement interdit de le diffuser, le distribuer ou le reproduire. Toute personne qui reçoit cette communication par erreur est priée de nous en avertir immédiatement, par téléphone 1-888-865-2284 et détruire cet envoi selon nos directives.