Migrating Odoo

Odoo Migration

Use https://markdowntohtml.com/

Note: This process does not utilise Python virtualenv which seems to be the best practice for this sort of deployment

Backup

These commands taking place on “host” where the production instance is running
The production instance is consistently named “odoo11-live” (linux user, /opt location, filestore, DB name, DB user)

Stop Odoo and ensure it is not running


root@host:~# service odoo11-live stop
root@host:~# ps awxf | grep odo
 4458 pts/1    S+     0:00          \_ grep --color=auto odo
```

## Confirm name of database to backup

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


## Check DB exists

root@host:~# su – postgres
postgres@host:~$ psql
psql (9.5.12)
Type “help” for help.

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-dev | odoo11-dev | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
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)

postgres=# \q
postgres@host:~$


## Backup the DB -O or --no-owner for setting no owner on dump.

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


## Move the backup file to /root

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


## Backup the Odoo application

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


## Move the backup file to /root

root@host:/opt# cd
root@host:~# mv /opt/20180430-odoo11-live.tar.gz .


## Start Odoo again

root@host:~# service odoo11-live start


# Restore These commands taking place on “dev” where the development instance is to be restored The development instance is consistently named “odoo11-dev” (linux user, /opt location, filestore, DB name, DB user, Apache VirtualHost) ## Copy the backup files from the production host

root@dev:~# cd /opt
root@dev:/opt# scp root@host:20180430* .
20180430-odoo11-live.sql.gz 100% 2416KB 2.4MB/s 00:00
20180430-odoo11-live.tar.gz 100% 407MB 135.7MB/s 00:03


## Extract application & rename

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


## Prepare linux user Add Linux user (set a password), change ownership of application directory
.

root@dev:/opt# adduser odoo11-dev –home /opt/odoo11-dev
root@dev:/opt# chown -R odoo11-dev:odoo11-dev odoo11-dev


## 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@test:/opt/odoo11-dev/.local/share/Odoo/filestore# cd /opt


## Create the log directory

root@dev:/opt# mkdir /var/log/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 DB User and the DB and import

root@dev:/opt# su – postgres
postgres@dev:~$ createuser -d -P odoo11-dev # Password must match that in /etc/odoo11-dev.conf

postgres@dev:~$ su – odoo11-dev # Use the password you set above

odoo11-dev@dev:~$ createdb odoo11-dev
odoo11-dev@dev:~$ gunzip -c /opt/20180430-odoo11-live.sql.gz | psql odoo11-dev
odoo11-dev@dev:~$ logout
postgres@test:~$ logout


## Install Python requirements

root@dev:~# apt-get install python3 python3-pip
root@dev:~# apt-get install wget git bzr python-pip gdebi-core -y
root@dev:~# apt-get install python-pypdf2 python-dateutil python-feedparser python-ldap python-libxslt1 python-lxml python-mako python-openid python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-reportlab python-simplejson python-tz python-vatnumber python-vobject python-webdav python-werkzeug python-xlwt python-yaml python-zsi python-docutils python-psutil python-mock python-unittest2 python-jinja2 python-pypdf python-decorator python-requests python-passlib python-pil -y
root@dev:~# pip3 install pypdf2 Babel passlib Werkzeug decorator python-dateutil pyyaml psycopg2 psutil html2text docutils lxml pillow reportlab ninja2 requests gdata XlsxWriter vobject python-openid pyparsing pydot mock mako Jinja2 ebaysdk feedparser xlwt psycogreen suds-jurko pytz pyusb greenlet xlrd 
root@dev:~# apt-get install python3-suds -y
root@dev:~# apt-get install node-clean-css -y
root@dev:~# apt-get install node-less -y
root@dev:~# apt-get install python-gevent -y
root@dev:~# pip3 install phonenumbers
root@dev:~# pip3 install gevent


## Install wkhtmltopdf

root@dev:/opt# wget https://downloads.wkhtmltopdf.org/0.12/0.12.1/wkhtmltox-0.12.1_linux-trusty-amd64.deb
root@test:/opt# dpkg -i wkhtmltox-0.12.1_linux-trusty-amd64.deb


## Prepare Config

root@dev:/opt# scp root@host:/etc/odoo11-live.conf .
root@dev:/opt# cat odoo11-live.conf | sed ‘s/odoo11-live/odoo11-dev/g’ > odoo11-dev.conf
root@dev:/opt# mv odoo11-dev.conf /etc


### 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/


## Prepare Init Script

root@dev:~# scp root@host:/etc/systemd/system/odoo11-live.service .
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/


### Inspect Inspect the init script and ensure: * python3 path is valid; and * user and group are correct ie. odoo-dev in this case ### Sample

[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


## Test Start Odoo and Monitor Log

root@dev:~# su – odoo11-dev
odoo11-dev@dev:~$ python3 /opt/odoo11-dev/server/odoo-bin -c /etc/odoo11-dev.conf

Control-C to shut down

odoo11-dev@dev:~$ logout


## Test Init Script

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


## Enable Start on 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


## 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

(Provide customer’s email address – domain owner)


## Apache Virtual Host configuration Create the site in /etc/apache2/sites-available/odoo11-dev.conf This 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.


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



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



## Enable the config 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
“`

Leave a Reply