Release Management/Testing environments/Production to testing replication

From InfiniteERP Wiki
Revision as of 17:54, 13 August 2022 by Wikiadmin (talk | contribs) (Created page with "== Introduction == In a production Openbravo ERP system it is usual and recommended to have a testing environment. Among its ben...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

In a production Openbravo ERP system it is usual and recommended to have a testing environment. Among its benefits we could highlight the ability for end users to test new features in advance and for the system integrator to test new customization deployments.

Before any of these testings happen, it is important to make sure that the ERP in the testing environment is identical to the one in the production environment. So this article explains the process of replicating an Openbravo ERP production system into a testing environment.

Requirements

  • Two isolated servers with the Openbravo ERP environment stack working properly. One will be named production environment and the other one testing environment.
  • There is an Openbravo ERP installation already running in the production environment.

General workflow

  • Production environment: save a database dump, the source code root directory and the Tomcat webapp in a archive file.
  • Transfer this archive file into the testing environment.
  • Restore the database dump, the source code and the Tomcat webapp in the testing environment.

Production: get a Openbravo ERP snapshot

First of all, create a basic directory structure where we'll save the snapshot. Example of the desired structure:

/tmp/openbravo-erp/
|-- database
|-- sources
`-- webapp

Database dump

Information you need to gather from the config/Openbravo.properties file in the production Openbravo ERP environment:

  • Database system: Oracle or PostgreSQL.
  • Database name (PostgreSQL) or SID (Oracle) in which Openbravo ERP is running.
  • The port in which the database is running.
  • User name that owns the Openbravo ERP database and its password.

To create a dump in Oracle, replace DB_USER and ORACLE_SID with the correct values you have just gathered:

exp DB_USER@ORACLE_SID file=/tmp/openbravo-erp/database/db_backup.dmp log=/tmp/openbravo-erp/database/db_backup.log owner=DB_USER statistics=none

To create a dump in PostgreSQL, replace DB_USER and DB_NAME with the correct values you have just gathered:

pg_dump -U DB_USER -h localhost -F c -b -v -f /tmp/openbravo-erp/database/db_backup.dmp DB_NAME

Source code tree

Openbravo ERP version 2.50 requires the source tree to be available in order for the modularity feature to work properly. So in this step copy the entire source tree into the /tmp/openbravo-erp/sources/ directory. If you are not sure of what this directory is, check the value of the source.path property in the config/Openbravo.properties file. Make sure that you preserve the file permissions and owners during this copy process (e.g. use cp -a in UNIX based systems).

Tomcat webapp

The Openbravo ERP webapp in Tomcat is a generated directory. A snapshot however requires having an exact copy, without taking care of whether there are some compilation issues in the process of generating this directory. This is why we'll back it up entirely.

So first all stop Tomcat, and then copy the $CATALINA_BASE/webapps/CONTEXT_NAME directory into /tmp/openbravo-erp/webapp/. Make sure that you preserve the file permissions and owners during this copy process (e.g. use cp -a in UNIX based systems). If you have troubles locating this directory, check the value of the context.name property in config/Openbravo.properties file, and also note that $CATALINA_BASE is equal to $CATALINA_HOME in some systems. Once this is copied you can start Tomcat.

Archive file

The next step is to archive the /tmp/openbravo-erp directory into a compressed file, so that it can easily be transferred into the testing environment. We will reference this archive file as openbravo-erp.tar. Use an archiving capable of saving the permissions and owner information, such as tar.

Transfer the archive file

Transfer the archive file created in the production environment into the testing environment. You can use a hard drive, SSH, FTP or any other transfer mechanism for this task.

Testing: apply the snapshot

Archive file

Unarchive the transferred archive file and place it in a known location. For example in the same directory as in the production system:

/tmp/openbravo-erp/
|-- database
|-- sources
`-- webapp

In the case of tar, use the -p to unarchive the files preserving the original owner and permissions.

Database dump

Information you need to gather from the database dump creation step:

  • Database system: Oracle or PostgreSQL.
  • Database name (PostgreSQL) or SID (Oracle) in which Openbravo ERP is running.
  • The port in which the database is running.
  • User name that owns the Openbravo ERP database and its password.

To create the database use and import the dump in Oracle, replace DB_USER, DB_PASSWORD and ORACLE_SID with the correct values you have just gathered:

sqlplus system@ORACLE_SID
CREATE USER DB_USER IDENTIFIED BY DB_PASSWORD
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP;

grant create session     to DB_USER;
grant alter  session     to DB_USER;
grant create table       to DB_USER;
grant create procedure   to DB_USER;
grant create trigger     to DB_USER;
grant create view        to DB_USER;
grant create sequence    to DB_USER;
alter user DB_USER quota unlimited on users;

quit

imp DB_USER@ORACLE_SID file=/tmp/openbravo-erp/database/db_backup.dmp log=/tmp/db_backup_import.log fromuser=DB_USER touser=DB_USER


To create a dump in PostgreSQL, replace DB_USER and DB_NAME with the correct values you have just gathered:

psql -d postgres -U postgres -h localhost
CREATE ROLE DB_USER LOGIN PASSWORD 'DB_PASSWORD' SUPERUSER CREATEDB CREATEROLE VALID UNTIL 'infinity';
UPDATE pg_authid SET rolcatupdate=true WHERE rolname='DB_USER';
CREATE DATABASE DB_NAME WITH ENCODING='UTF8' OWNER=DB_USER;
\q

pg_restore -i -U DB_USER -d DB_NAME -h localhost -v -O /tmp/openbravo-erp/database/db_backup.dmp
vacuumdb -U DB_USER -h localhost -d DB_NAME -f -z -v

Source code tree

Copy the sources directory (e.g. /tmp/openbravo-erp/sources/OpenbravoERP) into the same location in which they were in the production system. If you are not sure of what this directory is, check the value of the source.path property in the config/Openbravo.properties file. Make sure that you preserve the file permissions and owners during this copy process (e.g. use cp -a in UNIX based systems).

Tomcat webapp

First all stop Tomcat, and then copy the /tmp/openbravo-erp/webapp/CONTEXT_NAME directory into $CATALINA_BASE/webapps/. Make sure that you preserve the file permissions and owners during this copy process (e.g. use cp -a in UNIX based systems). Note that $CATALINA_BASE is equal to $CATALINA_HOME in some systems. Once this is copied you can start Tomcat.

Verification

As a first step verify that Openbravo ERP is working as expected and that the data is the same as in the production environment. Additionally, this is a check list of missed issues during the replication process:

  • You have used the same database user name, password and database names as in the production environment.
  • The file owner, group and permissions in the source tree directory are correct.
  • The file owner, group and permissions in the Openbravo ERP Tomcat webbapp directory are correct.
  • The Openbravo ERP source code directory

Command line tool

Openbravo has developed a command line tool that uses the procedure described in this document. Check the instructions.