Knowledgebase

Question About Servers

How to Migrate Your Odoo Instance to a Different Server Print

  • 44

This guide covers all the necessary steps required to migrate Odoo from one server to another (Ubuntu). 

 

Odoo Migration

The example below assumes that you are migrating a live version from the production server to a development server.

NOTE: The production instance is consistently named. For example, Odoo 11 instance will be named odoo11-live (linux user, /opt directory, configuration file, systemctl file, filestore, DB name, DB user).

We will migrate the Odoo 11 instance named odoo11-live to a development server, where the name will be odoo11-dev. You should change the version number depending on the Odoo version that you're migrating. 

 

Backup Your Odoo Instance

The steps in this section should be executed on the production server (where an active Odoo instance is running) as the root user. 

 

Stop Odoo:

root@host:~# service odoo11-live stop

 

Ensure Odoo is not running

root@host:~# ps awxf | grep odo

4458 pts/1 S+ 0:00 \_ grep --color=auto odo 

 

Backup the Database

Confirm the name of the database to backup:

root@host:~# grep db_name /etc/odoo11-live.conf
db_name = odoo11-live

 

Now, check if the database exists in PostgreSQL.

Switch to the user postgresql and enter PostgreSQL shell:

root@host:~# su - postgres

postgres@host:~$ psql
psql (9.5.12)
Type "help" for help.

 

List all the databases and confirm that the odoo11-live database exists in the Name column:

postgres=# \l

                                    List of databases
    Name     |    Owner    | Encoding |   Collate   |    Ctype    |   Access privileges
-------------+-------------+----------+-------------+-------------+-----------------------
 acuto       | acuto       | UTF8     | en_US.UTF-8 | en_US.UTF-8 | acuto=CTc/acuto
 odoo11-live | odoo11-live | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 odoo11live  | postgres    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +
             ||||| postgres=CTc/postgres+
             ||||| odoo11=CTc/postgres
 postgres    | postgres    | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0   | postgres    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
             ||||| postgres=CTc/postgres
 template1   | postgres    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
             ||||| postgres=CTc/postgres
(7 rows)

 

Leave the PostgreSQL shell:

postgres=# \q

 

Backup the database into a file and logout from the postgresql user.

postgres@host:~$ pg_dump -O odoo11-live | gzip > 20201010-odoo11-live.sql.gz

postgres@host:~$ logout

Note:  The -O (or --no-owner) parameter will make sure that there is no owner on the dumped database.

Note: put the today's timestamp at the beginning of a filename.

 

Move the database backup file to /root

root@host:~# mv /var/lib/postgresql/20201010-odoo11-live.sql.gz .

Note: change postgresql to pgsql if you encounter an error.

 

Backup the Odoo Application

Go to the /opt directory and create an archive from the Odoo application directory (odoo11-live)

root@host:~# cd /opt

root@host:/opt# tar czf /root/20180430-odoo11-live.tar.gz odoo11-live

 

Check if Odoo Instance Has a Virtual Environment for Python

root@host:~# cat /etc/systemd/system/odoo-live.service | grep Exec

ExecStart=/opt/odoo11-live/odoo11-venv/bin/python3 /opt/odoo11-live/server/odoo-bin -co /etc/odoo11-live.conf

The first path after ExecStart is the Python executable path. If there is venv in the path, then Odoo is using a virtual environment and you don't need to do anything. 

If an Odoo Instance doesn't have a virtual environment, the path will look similar to this: /usr/bin/python3. If that's the case, proceed to the next step. Otherwise ignore it.

 

Get a List of Installed Python Packages

This step is only necessary if your Odoo Instance does not have its own virtual environment for Python. 

Save a list of installed python packages on the system into a requirements.txt file and put it in the /root directory.

root@host:~# pip3 freeze > /root/requirements.txt

 

Start Odoo Again

root@host:~# service odoo11-live start

 

Migrating the Odoo Instance

The steps from this section should be executed on the development server (where a development Odoo instance should be running) as the root user. 

NOTE: The development instance is consistently named. For example, Odoo 11 instance will be named odoo11-dev (linux user, /opt directory, configuration file, systemctl file, filestore, DB name, DB user, Apache).

 

Get the Odoo Backups from the Production Server

root@dev:~# cd /opt

root@dev:/opt# scp root@host:20201010* .

20201010-odoo11-live.sql.gz                                                                                                                      
20201010-odoo11-live.tar.gz  

Note: change host to the hostname (or IP address) of your production server. Change 20201010 to your actual timestamp.

 

Copy the config file and rename it to odoo11-dev.conf

root@dev:/opt# scp root@host:/etc/odoo11-live.conf /etc/odoo11-dev.conf

 

Extract the Odoo Application Directory & Rename It

root@dev:/opt# tar xf 20201010-odoo11-live.tar.gz

root@dev:/opt# mv odoo11-live odoo11-dev

Note: change 20201010 to your actual timestamp.

 

Rename the Odoo filestore

The Odoo filestore must match the name of the Odoo database.

root@dev:/opt# cd odoo11-dev/.local/share/Odoo/filestore/

root@dev:/opt/odoo11-dev/.local/share/Odoo/filestore# mv odoo11-live odoo11-dev

root@dev:/opt/odoo11-dev/.local/share/Odoo/filestore# cd /opt

 

Create the Log Directory

root@dev:/opt# mkdir /var/log/odoo11-dev

 

Create a Linux User for Odoo

Create a linux user named odoo11-dev and make it the owner of the application directory and the log file.

root@dev:/opt# adduser odoo11-dev --home /opt/odoo11-dev

root@dev:/opt# chown -R odoo11-dev:odoo11-dev odoo11-dev

root@dev:/opt# chown odoo11-dev:odoo11-dev /var/log/odoo11-dev

 

Install PostgreSQL

root@dev:/opt# apt update

root@dev:/opt# apt upgrade

root@dev:/opt# apt install postgresql -y

 

Create the database user odoo11-dev and the database odoo11-dev.

root@dev:/opt# su - postgres

postgres@dev:~$ createuser -d odoo11-dev

postgres@dev:~$ logout

root@dev:/opt# su - odoo11-dev

odoo11-dev@dev:~$ createdb odoo11-dev

 

Import the production Odoo database into the odoo11-dev database

odoo11-dev@dev:~$ gunzip -c /opt/20201010-odoo11-live.sql.gz | psql odoo11-dev 

odoo11-dev@dev:~$ logout 

 

Install System Packages

root@dev:/opt# sudo apt-get install python3 python3-pip python3-suds wget git bzr gdebi-core libxml2-dev libxslt1-dev zlib1g-dev libsasl2-dev libldap2-dev libssl-dev -y

 

Install additional node packages:

root@dev:/opt# sudo apt-get install node-clean-css node-less git -y
 
Install Python 3.6

The default Python version will not work with Odoo 13. We need to install the 3.6 version, along with all the needed tools.

 

Add a remote repository with Python 3.6

root@dev:/opt#  sudo add-apt-repository ppa:deadsnakes/ppa


Install Python 3.6

root@dev:/opt# sudo apt install python3.6 python3.6-dev python3.6-venv

 

If your production Odoo instance did not have a virtual environment, proceed to the next step. Otherwise ignore it.

 

Create a Virtual Environment and Install Python Packages

Create a virtual environment in the odoo11-dev directory.

root@dev:/opt# cd /opt/odoo11-dev && python3 -m venv odoo11-venv

 

Activate the virtual environment:

root@dev:/opt# source odoo13-venv/bin/activate

 

Copy the requirements.txt file from the production server.

(odoo11-venv) root@dev:/opt# scp root@home:requirements.txt .

 

The library and module details are stored in the requirements.txt file. Use it to install all of the modules at once:

(odoo11-venv) root@dev:/opt# pip3 install -r requirements.txt

 

Deactivate the virtual environment:

(odoo11-venv) root@dev:/opt# deactivate
 
Install wkhtmltopdf

Download the package

root@dev:/opt# sudo wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb

 

Additional packages are required for Wkhtmltopdf to run. Install them with the following commands:

root@dev:/opt# sudo apt-get install libjpeg-turbo8 libjpeg-turbo8 libxrender1 xfonts-75dpi xfonts-base -y
root@dev:/opt# sudo apt-get install fontconfig

Note: there may be an error during this step. It's normal. The next command will fix it.

root@dev:/opt# sudo apt-get install -f

 

Install the package:

root@dev:/opt# sudo dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb

 

Edit the Configuration File

Change all instances of the odoo11-live string to odoo11-dev in the configuration file.

root@dev:/opt# cat /etc/odoo11-dev.conf | sed 's/odoo11-live/odoo11-dev/g' > /etc/odoo11-dev.conf

 

The configuration file will look similar to this:

Sample
[options]
admin_passwd = snip
db_host = localhost
db_port = 5432
db_user = odoo11-dev
db_password = odoo
db_name = odoo11-dev
addons_path = /opt/odoo11-dev/server/addons,/opt/odoo11-dev/custom_addons
logfile = /var/log/odoo11-dev/odoo11-dev.log
xmlrpc_port = 8089
data_dir = /opt/odoo11-dev/.local/share/Odoo/

Note: make sure that the db_user, db_name, logfile, data_dir, and addons_path correspond to the correct names and paths (especially addons!)

 

Create a Systemctl Service File

Copy the systemctl service file from the production server: 

root@dev:~# scp root@host:/etc/systemd/system/odoo11-live.service .

 

Change all instances of the odoo11-live string to odoo11-dev in the systemd service file, then put the file in the correct directory.

root@dev:~# cat odoo11-live.service | sed 's/odoo11-live/odoo11-dev/g' > odoo11-dev.service

root@dev:~# mv odoo11-dev.service /etc/systemd/system/

 

The file should look like this: 

[Unit]
Description=odoo11-dev
After=odoo11-dev.target

[Service]
Type=simple
SyslogIdentifier=odoo11-dev
PermissionsStartOnly=true
User=odoo11-dev
Group=odoo11-dev
ExecStart=/opt/odoo11-dev/odoo11-venv/bin/python3 /opt/odoo11-dev/server/odoo-bin -c /etc/odoo11-dev.conf
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target

Note: make sure that the User, Group are set to odoo11-dev

Note: Make sure that ExecStart has the correct parameters (python path, Odoo executable, and config)

Execute Odoo and Monitor the Log

root@dev:~# su - odoo11-dev

odoo11-dev@dev:~$ /opt/odoo11-dev/odoo11-venv/bin/python3 /opt/odoo11-dev/server/odoo-bin -c /etc/odoo11-dev.conf

 

If all is well, stop the process and logout from the odoo11-dev user.

odoo11-dev@dev:~$ logout

 

Start Odoo With Systemctl

root@dev:~# systemctl daemon-reload

root@dev:~# service odoo11-dev start

root@dev:~# service odoo11-dev status

* odoo11-dev.service - odoo11-dev
   Loaded: loaded (/etc/systemd/system/odoo11-dev.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-04-30 10:36:49 UTC; 3s ago
<snip>

 

If all is well, enable the Odoo service so that it starts at system boot:

root@dev:/etc/systemd/system# systemctl enable odoo11-dev.service

Created symlink from /etc/systemd/system/multi-user.target.wants/odoo11-dev.service to /lib/systemd/system/odoo11-dev.service.

 

Install Apache

root@dev:~# apt install apache2 -y

root@dev:~# a2enmod proxy_http

root@dev:~# a2enmod ssl

root@dev:~# a2enmod rewrite

 

Enable proxy-http and ssl

root@dev:~# a2enmod proxy_http

root@dev:~# a2enmod ssl

root@dev:~# a2enmod rewrite

 

Prepare LetsEncrypt for SSL

root@dev:~# apt install software-properties-common -y

root@dev:~# add-apt-repository ppa:certbot/certbot

root@dev:~# apt update

root@dev:~# apt install python-certbot-apache -y

root@dev:~# certbot --apache certonly

Note: Provide customer's email address - domain owner

 

Apache Virtual Host Configuration

Create the site in /etc/apache2/sites-available/odoo11-dev.conf

root@dev:~# nano /etc/apache2/sites-available/odoo11-dev.conf

 

Paste the following configuration into the file.

Note that the configuration was created for outsourceitsupport.com. Search and replace all instances of outsourceitsupport.com with whatever hostname is being used for the migrated Odoo instance.

<VirtualHost *:80>
        DocumentRoot /var/www/html
        ServerName outsourceitsupport.com

        RewriteEngine on
        RewriteCond %{SERVER_NAME} =outsourceitsupport.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

        ErrorLog ${APACHE_LOG_DIR}/outsourceitsupport.com.error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/outsourceitsupport.com.access.log combined
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
        DocumentRoot /var/www/html
        ServerName outsourceitsupport.com

        ProxyPass /        http://localhost:8089/ retry=0
        ProxyPassReverse / http://localhost:8089/ retry=0

        SSLCertificateFile /etc/letsencrypt/live/outsourceitsupport.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/outsourceitsupport.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

        ErrorLog ${APACHE_LOG_DIR}/outsourceitsupport.com-ssl.error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/outsourceitsupport.com-ssl.access.log combined
</VirtualHost>
</IfModule>

 

Enable the Configuration File and Reload Apache

root@dev:/etc/apache2/sites-available# ln -s /etc/apache2/sites-available/odoo11-dev.conf /etc/apache2/sites-enabled/

root@dev:/etc/apache2/sites-available# service apache2 reload

Was this answer helpful?

« Back

Enterprise-Grade Hardware

  • Samsung
  • Juniper
  • Western Digital
  • Supermicro
  • LSI
  • Intel
  • R1Soft Backups
  • cPanel
  • MySQL
  • Parallels
  • HP Partner