One of the most critical components in migrating SAP Commerce to the SAP Cloud is moving existing data smoothly from the on-premise environment to the SAP CCV2. This process involves two primary tasks: migrating the database and the media files. This article will focus on the media files and provide a detailed guide on migrating them efficiently to SAP Commerce Cloud.

Overview of SAP Commerce Media Storage Strategies

SAP Commerce offers different strategies for media storage. In an on-premise environment, the default strategy is localFileMediaStorageStrategy, implemented by the de.hybris.platform.media.storage.impl.LocalFileMediaStorageStrategy. This strategy stores media files in a local folder on the system where SAP Commerce is running. A shared directory is used in a clustered environment, accessible by all SAP Commerce nodes via NFS (Network File System).

In contrast, the recommended strategy for SAP Commerce Cloud is windowsAzureBlobStorageStrategy, implemented by the de.hybris.platform.azure.media.storage.WindowsAzureBlobStorageStrategy from the azurecloud extension. This strategy stores media files in Azure Blob Storage containers, leveraging cloud-native infrastructure for scalability and performance.

SAP Commerce Cloud provides an Azure storage account for each environment. While this storage account is primarily used to connect external systems with SAP Commerce’s data import/export processes, such as hot folders, it can also be leveraged to store all media files for your SAP Commerce instance. This flexibility makes Azure storage optimal for smooth media data migration.

These media storage strategies can be configured globally for the entire system or specifically for individual media folders.

  • Global configuration for Azure Blob Storage looks like this:
  • media.default.storage.strategy=windowsAzureBlobStorageStrategy
  • media.globalSettings.windowsAzureBlobStorageStrategy.connection= DefaultEndpointsProtocol=http;AccountName=yourAccountName;AccountKey=yourAccountKey
  • To configure for specific media folders, use properties like this:

  • media.folder..storage.strategy=windowsAzureBlobStorageStrategy
  • media.folder..connection=DefaultEndpointsProtocol=http;AccountName=yourAccountName;AccountKey=
    yourAccountKey
media storage strategies

Migrating Media Files from On-Premise to the Cloud

on-premise to ccv2 media migration

To migrate media files from an on-premise system to the cloud, we assume you’re moving from localFileMediaStorageStrategy to windowsAzureBlobStorageStrategy globally. The process involves transferring all media files from a local file system to Azure Blob Storage, and we’ll break it down step-by-step.

How Media Locations are Determined

When migrating media, it’s crucial to understand how file locations are calculated for each strategy.

For the localFileMediaStorageStrategy:

  • File path: <media-folder>/sys_master/<location>

  • media-folder: Root path for media files (defined by media.replication.dirs, which defaults to ${HYBRIS_DATA_DIR}/media).
  • sys_master: A standard subpath added by the LocalFileMediaStorageStrategy, where master corresponds to the tenant ID.
  • location: The location attribute of the Media.

For the windowsAzureBlobStorageStrategy:

  • Blob location: https://<storage-account-name>.blob.core.windows.net/<container-name>/<location>
  • storage-account-name: The Azure account name.
  • container-name: The name of the Azure container where blobs are stored, built like sys-master-[folder-qualifier], where sys-master is a standard prefix based on the tenant ID and [folder-qualifier] is the qualifier attribute of the MediaFolder
  • location: The location attribute of the media.

You can map media from the local storage to the correct Azure storage container using the media folder and location information.

Important Considerations When Migrating Media Files

If you plan to move all files in a specific MediaFolder, it’s important to note how the location attribute is built using the localFileMediaStorageStrategy. This will help you identify the files to be copied from the local filesystem.

The location is structured as follows:

location = folder-path/hxx/hxx/PK.file-extension

Where:

  • folder-path is the path attribute of the MediaFolder.
  • hxx/hxx is an autogenerated 2-depth path structure.
  • PK is the Media’s Primary Key (PK).
  • file-extension is derived from the Media’s MIME type.

This breakdown allows you to create a comprehensive strategy for migrating each MediaFolder from local storage to the corresponding Azure container.

Step-by-Step Media Migration Process

1. Query Existing Media Folders

The first step is to query all existing media folders in your on-premise SAP Commerce system. Use the following query to retrieve media folders and their paths:

Copy to Clipboard

Example results:

 

Qualifier Path
root NULL
images images
backofficethemes backoffice/themes

2. Prepare Azure Storage Environment

SAP Commerce Cloud provides an Azure Storage Account for each environment. You can access this storage account using its name and key, which are both accessible through the SAP Cloud Portal.

Use Microsoft Azure Storage Explorer to connect and create a SAS Token (Shared Access Signature) with Write access. For each media folder, create a corresponding Azure container with the following naming convention:

Copy to Clipboard

Examples:

  • sys-master-images
  • sys-master-impex
  • sys-master-backofficethemes

You can create these containers manually via Azure Storage Explorer or through the following command:

Copy to Clipboard

3. Copy Media Files to Azure

To transfer media files from your on-premise environment to Azure Blob Storage, use azcopy, a Microsoft tool designed to handle file transfers to and from Azure.

The general command format to copy media files is as follows:

Copy to Clipboard

Examples:

Images folder:

In this example, the qualifier and path attributes of the MediaFolder have the same value.

Copy to Clipboard

 Backoffice themes folder:

In this case, the qualifier and path attributes of the MediaFolder have different values.

Copy to Clipboard

Special Case: Root Folder Migration

The root folder requires special attention because its media files are stored directly under sys_master, without a subpath. To avoid copying files from other media folders, use a more specific pattern like:

Copy to Clipboard

This will only copy files whose location begins with an “h,” corresponding to the autogenerated path for files in the root folder. Note that if you have other media folders starting with “h” they will also be copied. Alternatively, you can create a bash script to iterate each folder that starts with h followed by only two characters and copy each individually:

Copy to Clipboard

4. Ensure Cloud Configuration for Azure Storage

To finish the process, confirm that the SAP Commerce Cloud environment uses the windowsAzureBlobStorageStrategy. Ensure the following properties are set:

Copy to Clipboard

Additionally, verify that all relevant database records for the media (including location and mediaFolder attributes) have been migrated to the cloud, ensuring the files are correctly mapped in the new environment.

Automation with Groovy Script

To make the migration process faster, you can use a Groovy script in your on-premise environment’s hAC (Hybris Administration Console). This script generates the necessary azcopy commands for each media folder:

Copy to Clipboard

Delta Migration for Go-Live

As part of the migration process, an initial transfer of all media files is typically performed days or weeks before the official go-live to validate the cloud environment. However, during this interim period, the on-premise system remains active, generating new media data that must be incorporated before the final switch. To address this, a delta migration is performed on the go-live date, ensuring any newly created files are transferred to the cloud. Instead of copying all files again, you can optimize the process by using the azcopy sync command, which detects and copies only the files that have changed, making the migration faster and more efficient.

Example command:

Copy to Clipboard

Conclusion

Migrating media files to SAP Commerce Cloud can be complex, but it’s a seamless process with the right approach. For expert guidance and support, E-Turia’s team of SAP Commerce specialists can ensure a smooth migration tailored to your needs. Contact E-Turia through the form below to make your transition to the cloud effortless and efficient.