Technical mailing list archives

technical@mail.odoo.com

Avatar

Re: Database Restore Error

by
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):
        _logger.info('RESTORE DB: %s already exists', db)
        raise Exception("Database already exists")

    _create_empty_database(db)

    filestore_path = None
    with odoo.tools.osutil.tempdir() 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')]

        else:
            # <= 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 odoo.tools.exec_pg_command(pg_cmd, *pg_args):
            raise Exception("Couldn't restore database")

        registry = odoo.modules.registry.Registry.new(db)
        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
                env['ir.config_parameter'].init(force=True)
            if filestore_path:
                filestore_dest = env['ir.attachment']._filestore()
                shutil.move(filestore_path, filestore_dest)

            if odoo.tools.config['unaccent']:
                try:
                    with cr.savepoint():
                        cr.execute("CREATE EXTENSION unaccent")
                except psycopg2.Error:


Le jeu. 14 déc. 2017 à 13:10, Can Tecim <cant@projetgrup.com> 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 <arlosyst@gmail.com>:
So, it will restore all the images and be a proper restore. right?
On Thu, Dec 14, 2017 at 11:20 PM, Can Tecim <cant@projetgrup.com> 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 <arlosyst@gmail.com>:
How do we restore ZIP backup via postgres?
On Thu, Dec 14, 2017 at 10:20 PM, Xavier Brochard <zeroheure@gmail.com> 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

_______________________________________________

_______________________________________________
Mailing-List: https://www.odoo.com/groups/technical-62
Post to: mailto:technical@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

--
Best Regards,,
Can Tecim, CTO
Projet Grup

_______________________________________________

_______________________________________________
Mailing-List: https://www.odoo.com/groups/technical-62
Post to: mailto:technical@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--
Best Regards,,
Can Tecim - Projet Grup

_______________________________________________
Mailing-List: https://www.odoo.com/groups/technical-62
Post to: mailto:technical@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

--

JÉRÔME THÉRIAULT 
Analyste-programmeur, système Odoo

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

AVIS DE CONFIDENTIALITÉ
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. 

Reference