System Administrator

How to export all websites with a Groovy script?

Question

How to export all websites with a Groovy script?

Answer

Here is a script that can do that (only tested with Jahia 8.1.1.1):

def siteList = ServicesRegistry.getInstance().getJahiaSitesService().getSitesNodeList();
def exportPath = "test2";
def onlyStaging = false;
def params = new HashMap<>(14);

params.put(ImportExportService.VIEW_CONTENT, true);
params.put(ImportExportService.VIEW_VERSION, false);
params.put(ImportExportService.VIEW_ACL, true);
params.put(ImportExportService.VIEW_METADATA, true);
params.put(ImportExportService.VIEW_JAHIALINKS, true);
params.put(ImportExportService.VIEW_WORKFLOW, true);
params.put(ImportExportService.SERVER_DIRECTORY, exportPath);
params.put(ImportExportService.INCLUDE_ALL_FILES, true);
params.put(ImportExportService.INCLUDE_TEMPLATES, true);
params.put(ImportExportService.INCLUDE_SITE_INFOS, true);
params.put(ImportExportService.INCLUDE_DEFINITIONS, true);
params.put(ImportExportService.INCLUDE_LIVE_EXPORT, !onlyStaging);
params.put(ImportExportService.INCLUDE_USERS, true);
params.put(ImportExportService.INCLUDE_ROLES, true);

def cleanupXsl = SettingsBean.getInstance().getJahiaEtcDiskPath() + "/repository/export/cleanup.xsl";
params.put(ImportExportService.XSL_PATH, cleanupXsl);

def importExportBaseService = ServicesRegistry.getInstance().getImportExportService();
importExportBaseService.exportSites(new ByteArrayOutputStream(), params, siteList);