The problem statement
The Hybris distribution requires around 3 GB of disk space and consists of 30,000 folders and around 134,000 files. I needed to have several Hybris instances preconfigured for specific purposes. There is nothing complicated about creating a fresh copy to have a completely separate instance. However, this process takes time, and the newly created distribution takes more than 3 GB of my SSD. It could be endured, but it makes me wait each time while 134,000 files and 30,000 folders are copied from one place to another.
Sometimes I need to check some assumptions on a fresh Hybris installation. However, once I change something in the configuration, that instance can no longer be called “fresh,” because these changes can irreversibly affect the initial state of the system. For example, some configuration changes can result in additional files being created in Hybris folders. These files may affect the next run or another configuration.
Hybris 6.1 has a feature named HybrisPlatformRole API, but it is not a solution for the task above because it changes the configuration of the instance. You won’t be able to work with two Hybris instances in parallel because they use the same filesystem, the same data folder, etc.
To avoid these problems, I create a fresh copy of Hybris each time I need to be free from the influence of these files and the database state. The faster I can create a fresh copy and test my code on it, the more effective I will be.
The solution
The approach explained below will allow you to create a fresh copy of Hybris on the same HDD in one minute. This copy will take ~500 MB because it shares some of the files with another instance.
For example, for the acceleratorfacades module, two folders are skipped, all root files are copied, and the remaining folders are symlinked to the original location. As a result, the cloned copy of the extension is much smaller than it would be if you copied all folders.

Results
Creating a new clone takes about a minute + initialization (8 min).
Configuration
To use the cloned version in parallel with the source version, you need to make the following changes in the configuration (local.properties):
- Ports
- WEB (HTTP, SSL)
- tomcat.http.port=19001
- tomcat.ssl.port=19002
- SOLR
- solrserver.instances.default.port=18983
- JMX
- tomcat.jmx.port=19003
- tomcat.jmx.server.port=19004
- Debug:
- tomcat.debugjavaoptions=-Xverify:none -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=18000,suspend=n -Dlog4j.configuration=log4j_init_tomcat.properties -Djava.util.logging.config.file=jdk_logging.properties
- WEB (HTTP, SSL)
- URLs
- storefront extension
- website.*
- media.*
- storefront extension
- Database credentials (if any)
You need to change the SOLR server port in the Facet Search Configuration. Example:
INSERT_UPDATE SolrEndpointUrl;solrServerConfig(name)[unique=true];url[unique=true];master[unique=true,default=false]
;$serverConfigName;http://localhost:18983/solr;trueCreating a clone
Linux
Download the Bash version here. It is similar to the Windows version.
Windows
Download the Windows version here. You can find some excerpts to demonstrate the concept.
create.sh
Change the first two lines in the script below. SOURCE is the folder where Hybris 6.1 is installed. TARGET is the folder to create.
set SOURCE=c:\hybris\h61
set TARGET=c:\hybris\h61_6
call create_auto0.bat %SOURCE% %TARGET%
call create_auto1.bat %SOURCE% %TARGET%
call create_auto2.bat %SOURCE% %TARGET%
call create_auto3.bat %SOURCE% %TARGET%create_auto0.bat
This script creates a base folder structure. Some folders are symlinks to the source Hybris folders.
Don’t copy the script below. Use this link instead.
@echo off
set SOURCE=%1
set TARGET=%2
mkdir %TARGET%
mkdir %TARGET%\hybris
mkdir %TARGET%\hybris\bin
mkdir %TARGET%\hybris\bin\platform
echo Creating symlinks for extensions...
mkdir %TARGET%\hybris\bin\ext-template\yempty
mkdir %TARGET%\hybris\bin\ext-template\yhacext
xcopy /E /Q /Y %SOURCE%\hybris\bin\ext-template\yempty\*.* %TARGET%\hybris\bin\ext-template\yempty\
xcopy /E /Q /Y %SOURCE%\hybris\bin\ext-template\yhacext\*.* %TARGET%\hybris\bin\ext-template\yhacext\
echo Creating symlinks for other folders
mklink /j %TARGET%\build-tools %SOURCE%\build-tools
mklink /j %TARGET%\c4c-integration %SOURCE%\c4c-integration
mklink /j %TARGET%\hybris-ems %SOURCE%\hybris-ems
mklink /j %TARGET%\hybris-Mobile-Apps-SDK %SOURCE%\hybris-Mobile-Apps-SDK
mklink /j %TARGET%\hybris-sbg %SOURCE%\hybris-sbg
mklink /j %TARGET%\installer %SOURCE%\installer
mklink /j %TARGET%\licenses %SOURCE%\licenses
echo Creating symlinks for platform folders...
mklink /j %TARGET%\hybris\bin\platform\apache-ant-1.9.1 %SOURCE%\hybris\bin\platform\apache-ant-1.9.1
mkdir %TARGET%\hybris\data\acceleratorservices
mkdir %TARGET%\hybris\data\backoffice
mkdir %TARGET%\hybris\data\luceneindex
mkdir %TARGET%\hybris\data\media
mkdir %TARGET%\hybris\data\solr
mkdir %TARGET%\hybris\log
mkdir %TARGET%\hybris\log\solr
mkdir %TARGET%\hybris\log\solrstats
mkdir %TARGET%\hybris\log\tomcat
mkdir %TARGET%\hybris\roles
mkdir %TARGET%\hybris\temp
echo Copying platform...
mkdir %TARGET%\hybris\bin\platform\bootstrap
xcopy /E /Q /Y %SOURCE%\hybris\bin\platform\bootstrap\*.* %TARGET%\hybris\bin\platform\bootstrap\
xcopy /Q /Y %SOURCE%\hybris\bin\platform\*.* %TARGET%\hybris\bin\platform\
mklink /j %TARGET%\hybris\bin\platform\resources %SOURCE%\hybris\bin\platform\resources
mklink /j %TARGET%\hybris\bin\platform\lib %SOURCE%\hybris\bin\platform\lib
mkdir %TARGET%\hybris\bin\platform\ext
xcopy /E /Q /Y %SOURCE%\hybris\bin\platform\ext %TARGET%\hybris\bin\platform\ext
mklink /j %TARGET%\hybris\bin\platform\tcServer %SOURCE%\hybris\bin\platform\tcServer
mkdir %TARGET%\hybris\bin\platform\tomcat\conf
xcopy /E /Q /Y %SOURCE%\hybris\bin\platform\tomcat\conf\*.* %TARGET%\hybris\bin\platform\tomcat\conf
mkdir %TARGET%\hybris\bin\platform\tomcat\lib
xcopy /E /Q /Y %SOURCE%\hybris\bin\platform\tomcat\lib\*.* %TARGET%\hybris\bin\platform\tomcat\lib
mkdir %TARGET%\hybris\bin\platform\tomcat\work
xcopy /E /Q /Y %SOURCE%\hybris\bin\platform\tomcat\work\*.* %TARGET%\hybris\bin\platform\tomcat\work
copy /E /Q /Y %SOURCE%\hybris\bin\platform\tomcat\tomcat_context.tpl %TARGET%\hybris\bin\platform\tomcat\tomcat_context.tpl
mkdir %TARGET%\hybris\bin\custom
mklink /j %TARGET%\hybris\bin\platform\tomcat\bin %SOURCE%\hybris\bin\platform\tomcat\bincreate_auto1.bat
Don’t copy the script below. Use this link instead.
@echo off
set SOURCE=%1
set TARGET=%2
mkdir %TARGET%
mkdir %TARGET%\hybris
mkdir %TARGET%\hybris\bin
mkdir %TARGET%\hybris\bin\platform
mkdir %TARGET%\hybris\bin\ext-accelerator\acceleratorcms
mkdir %TARGET%\hybris\bin\ext-accelerator\acceleratorcmshmc
mkdir %TARGET%\hybris\bin\ext-accelerator\acceleratorfacades
mkdir %TARGET%\hybris\bin\ext-accelerator\acceleratorservices
.... (800 lines) download the full scripts
copy %SOURCE%\hybris\bin\ext-template\yhacext\*.* %TARGET%\hybris\bin\ext-template\yhacext\
copy %SOURCE%\hybris\bin\ext-template\yoccaddon\*.* %TARGET%\hybris\bin\ext-template\yoccaddon\
copy %SOURCE%\hybris\bin\ext-template\ysmarteditmodule\*.* %TARGET%\hybris\bin\ext-template\ysmarteditmodule\
copy %SOURCE%\hybris\bin\ext-template\ywebservices\*.* %TARGET%\hybris\bin\ext-template\ywebservices\
create_auto2.bat
Don’t copy the script below. Use this link instead.
@echo off
set SOURCE=%1
set TARGET=%2
mklink /j %TARGET%\hybris\bin\ext-accelerator\acceleratorcms\resources %SOURCE%\hybris\bin\ext-accelerator\acceleratorcms\resources
mklink /j %TARGET%\hybris\bin\ext-accelerator\acceleratorcms\src %SOURCE%\hybris\bin\ext-accelerator\acceleratorcms\src
mklink /j %TARGET%\hybris\bin\ext-accelerator\acceleratorcms\testsrc %SOURCE%\hybris\bin\ext-accelerator\acceleratorcms\testsrc
mklink /j %TARGET%\hybris\bin\ext-accelerator\acceleratorcmshmc\hmc %SOURCE%\hybris\bin\ext-accelerator\acceleratorcmshmc\hmc
mklink /j %TARGET%\hybris\bin\ext-accelerator\acceleratorcmshmc\resources %SOURCE%\hybris\bin\ext-accelerator\acceleratorcmshmc\resources(1484 lines) download the full scripts
mklink /j %TARGET%\hybris\bin\ext-content\smartedit\src %SOURCE%\hybris\bin\ext-content\smartedit\src
mklink /j %TARGET%\hybris\bin\ext-content\smartedit\testsrc %SOURCE%\hybris\bin\ext-content\smartedit\testsrc
mklink /j %TARGET%\hybris\bin\ext-content\smartedit\web %SOURCE%\hybris\bin\ext-content\smartedit\webcreate_auto2.bat
@echo off
set SOURCE=%1
set TARGET=%2
xcopy /E /I /H %SOURCE%\hybris\bin\ext-content\bmecat\bin %TARGET%\hybris\bin\ext-content\bmecat\bin
xcopy /E /I /H %SOURCE%\hybris\bin\ext-content\bmecat\doc %TARGET%\hybris\bin\ext-content\bmecat\doc
xcopy /E /I /H %SOURCE%\hybris\bin\ext-content\bmecat\resources %TARGET%\hybris\bin\ext-content\bmecat\resources(125 lines) download the full scripts
xcopy /E /I /H %SOURCE%\hybris\bin\ext-backoffice\backoffice\resources %TARGET%\hybris\bin\ext-backoffice\backoffice\resources
xcopy /E /I /H %SOURCE%\hybris\bin\ext-backoffice\backoffice\testsrc %TARGET%\hybris\bin\ext-backoffice\backoffice\testsrc
xcopy /E /I /H %SOURCE%\hybris\bin\ext-backoffice\backoffice\web %TARGET%\hybris\bin\ext-backoffice\backoffice\web© Rauf Aliev, October 2016