IT Q&A

Welcome!

This community is for professionals and enthusiasts of our products and services.
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

0

Import an odoo db dump in postgres

Avatar
Corpuz Angel

Sometimes (especially for large dbs) we need to import the postgres dump directly in the db, this can be done easily in bash as follows.

Pre-requisites

  • login access to postgres with the odoo user

  • a bash shell

Notes

  • $DB_USER: odoo database user

  • $LOCAL_DBNAME: name of the local db where the dump will be imported

  • $SQLFILE: sql dump file

Importing the dump

  1. Create a new db as the odoodb user:
    > createdb --host=localhost --username="$DB_USER" "$LOCAL_DBNAME"

  2. Restore the database from the sql dump:
    > psql --host=localhost --username="$DB_USER" "$LOCAL_DBNAME" <  "$SQLFILE"

  3. [OPTIONAL] Copy the filestore (if available) in a new directory called $LOCAL_DBNAME in the datadir path

  4. Clean-up production data:

    1. Delete all smtp servers:
      > psql --host=localhost --username="$DB_USER" --dbname "$LOCAL_DBNAME" << EOF
      DELETE FROM ir_mail_server WHERE "name" != 'localhost'
      EOF

    2. Reset admin password to 'admin':
      > python_code="from passlib.context import CryptContext
      print CryptContext(['pbkdf2_sha512']).encrypt('admin')"
      crypt_pass=$(python -c "$python_code")
      > psql --host=localhost --username="$DB_USER" --dbname "$LOCAL_DBNAME" << EOF
      update res_users set password_crypt = '${crypt_pass}' where id = 2;
      EOF
      NOTE:if odoo version <12 then use id = 1

    3. Change database UUID:
      > new_uuid=$(uuidgen)
      > psql --host=localhost --username="$DB_USER" --dbname "$LOCAL_DBNAME" << EOF
      Update ir_config_parameter set value = '${new_uuid}' WHERE KEY='database.uuid';
      EOF


Avatar
Abbandona