Refresh SitecoreAI Lower Environments with Production Content

Software Architect
  • Twitter
  • LinkedIn

Keeping lower environments useful takes more than deploying the latest application code. After a website launches, authors continue adding pages, updating content and uploading media in the production environment. Over time, the content in development, testing or staging environments can fall well behind what the business actually uses.

That gap makes everyday work harder. Developers may have to recreate production content before they can reproduce an issue, and authors testing new functionality may be working with outdated pages and placeholder images. Refreshing a lower environment with current production content gives the team a more representative place to work.

The challenge is deciding what to bring across and what to preserve. A lower environment may already contain unfinished pages, new component definitions or work for another site. A refresh needs to copy the intended content while respecting those boundaries.

I built a PowerShell utility around Sitecore's Content Transfer API and Item Transfer API to make that operation repeatable. A JSON file defines the content to copy, and the same script runs locally or through Azure DevOps. The examples below use production as the source and a development environment as the destination; the same approach can target another lower environment by changing the connection settings.

How we used to refresh content

For traditional Sitecore installations, a database backup and restore was often the quickest route to a comprehensive refresh. It also replaced everything in the restored database, potentially overwriting development work. It required database access, compatible environments, and coordination around any separately stored media. Direct database restores are not an option available to us in SitecoreAI's managed SaaS environments.

Sitecore packages gave us more selective transfers. We could choose a content tree, create a ZIP, download it, upload it elsewhere, and decide how to handle collisions during installation. That worked for occasional changes, but repeated refreshes involved manual steps and careful package management.

More recently, Sitecore CLI serialization made it possible to pull items into YAML and push them to another environment. I still use serialization to deploy templates, renderings and configuration alongside application code. Large editorial trees, however, generate substantial file churn, and Sitecore specifically advises against using serialization for individual media assets at scale. Sitecore Content Serialization guidance

Sitecore removed the legacy Package Designer from SitecoreAI starting with base image 1.8.24 in July 2026. Where a configuration override still restores packaging, treat it as a temporary bridge as the feature is retired. New refresh workflows should use the supported transfer APIs. Package Designer replacement guidance

The APIs handle export and import

Sitecore introduced these APIs as the supported, programmatic replacement for moving content through legacy packages in SitecoreAI. Chunked transfers accommodate larger content and media transfers, with conflict handling specified before the operation starts. They are intended for moving content between existing SitecoreAI environments, including refreshing lower environments or promoting selected content between environments. Application code and the structural items it depends on still belong in the normal deployment process.

The two APIs cover different stages. The Content Transfer API prepares selected trees for export and provides the mechanisms to move their chunks into destination .raif files. These files are transfer artifacts stored in the destination environment. The Item Transfer API consumes them into the destination database. Uploading the content and importing it are separate operations. Sitecore's API walkthrough

The flexibility comes with orchestration work. Several requests start long-running operations and return before the work finishes. A client has to poll for export readiness, track chunk sets and identifiers, check that destination files are ready, start imports, and continue checking their status. It also needs to distinguish a confirmed failure from an operation that is still running, decide whether a retry is appropriate, and release resources at the right time.

You can make those calls manually in an API client to understand the process, but repeating the sequence for a sizeable refresh quickly becomes cumbersome. An application or orchestration layer makes the APIs practical for routine use. This is where my script provides its value: it manages the sequence and state checks around the individual requests.

The script coordinates the full lifecycle:

  1. Authenticate separately to the source and destination environments.
  2. Request the export for the configured database and paths, then wait until Sitecore has prepared the chunks.
  3. Stream the chunks sequentially from the source to the destination, preserving their bytes. No complete archive is downloaded to the machine running the script.
  4. Start and monitor each import once its destination file is ready.
  5. Clean up completed transfer resources and record the outcome in a JSON execution journal.

For media, the script reads Sitecore's IsMedia flag from each chunk's response header and forwards it during upload. You select the media-library paths; Sitecore decides how the export is chunked.

Retry behavior is explicit. By default, -RetryCount is 0; setting it above zero allows a bounded number of retries for a confirmed failed destination import. The script does not automatically replay failed exports or uploads, or restart imports simply because a request timed out. Those cases need inspection before another operation is started.

Files in the repository

The repository separates the transfer logic from the configuration and the optional pipeline that launches it:

FilePurpose
README.mdSetup instructions, configuration and parameter reference, and troubleshooting guidance.
Invoke-ContentTransfer.ps1Entry point for local and pipeline executions; loads the module and passes in the selected configuration and parameters.
SitecoreTransfer.psm1Reusable module that handles authentication, API orchestration, polling, import retries, journaling and cleanup.
prod-to-dev.ymlManually triggered Azure DevOps pipeline that supplies configuration and credentials, runs the entry script, and retains the execution journal.
config/*.jsonTransfer definitions selecting the database, item roots, scopes and merge strategies, with examples for content and media.

Define the scope in JSON

Start by deciding which areas of the lower environment should receive production content. A typical refresh includes pages beneath Home, global data sources, and the site's media library. Save those roots in refresh.json:

{
  "database": "master",
  "paths": [
    {
      "itemPath": "/sitecore/content/SiteCollection/Site/Home",
      "scope": "ItemAndDescendants",
      "mergeStrategy": "OverrideExistingItem"
    },
    {
      "itemPath": "/sitecore/content/SiteCollection/Site/Data",
      "scope": "ItemAndDescendants",
      "mergeStrategy": "OverrideExistingItem"
    },
    {
      "itemPath": "/sitecore/media library/Project/SiteCollection/Site",
      "scope": "ItemAndDescendants",
      "mergeStrategy": "OverrideExistingItem"
    }
  ]
}

Replace SiteCollection and Site with your actual site collection and site names. This is the utility's configuration format; the script constructs the underlying API request. database selects the database, itemPath selects a root, and ItemAndDescendants includes its subtree. Use SingleItem when only the selected item is required. Roots must not overlap.

References do not expand the transfer scope automatically. If a page uses shared media or global content elsewhere, include those roots explicitly. Consider dictionaries and author-maintained presentation or settings items too.

The example copies the production environment's master content, which can include unpublished authoring changes. It is not a snapshot limited to the pages currently visible on the public website. The destination must already contain compatible templates, renderings and required parent items with matching IDs; this utility does not validate those dependencies for you.

Decide what happens to existing content

The merge strategy determines what happens to content already in the destination:

StrategyEffect on the selected destination content
KeepExistingItemPreserves matching items and adds missing items.
OverrideExistingItemReplaces matching items and adds missing items, retaining destination-only items.
OverrideExistingTreeDeletes the destination root and its descendants, then writes the transferred tree.

Suppose the development environment contains an experimental page absent from production. With OverrideExistingItem, that page survives while matching pages receive production content. With OverrideExistingTree, it is removed. The same distinction applies to pages deleted from production since the last refresh: an item-level overwrite leaves their copies in the lower environment in place.

For a routine refresh that must preserve development work, I use OverrideExistingItem. For a baseline that must replace selected trees completely, OverrideExistingTree may be appropriate once any work unique to the destination has been preserved.

Strategies can differ by root. The optional -MergeStrategyOverride parameter applies one strategy to every configured root for that execution without editing the JSON. The supplied example configurations default to KeepExistingItem; the example above explicitly chooses overwrite behavior.

Run the refresh locally

The utility requires PowerShell 7. It does not require Sitecore PowerShell Extensions, the Sitecore CLI, or an application build.

Create separate environment automation clients in SitecoreAI Deploy → Credentials → Environment → Automation for the production and destination environments. Use the environment hostnames for the CM URLs. Existing deployment credentials should not be assumed to grant the required transfer access. Sitecore's walkthrough documents the Organization Admin or Organization Owner prerequisite.

For the first run, use SingleItem to transfer a representative item whose dependencies already exist in the destination. Validate the result before expanding to full content and media trees.

From the repository root, set the connection variables and run the entry script:

$env:SITECORE_TRANSFER_SOURCE_URL = 'https://xmc-mycustomertenant-sitecoreai-prod.sitecorecloud.io/'
$env:SITECORE_TRANSFER_DESTINATION_URL = 'https://xmc-mycustomertenant-sitecoreai-dev.sitecorecloud.io/'
$env:SITECORE_TRANSFER_SOURCE_CLIENT_ID = 'REPLACE_WITH_SOURCE_CLIENT_ID'
$env:SITECORE_TRANSFER_SOURCE_CLIENT_SECRET = 'REPLACE_WITH_SOURCE_CLIENT_SECRET'
$env:SITECORE_TRANSFER_DESTINATION_CLIENT_ID = 'REPLACE_WITH_DESTINATION_CLIENT_ID'
$env:SITECORE_TRANSFER_DESTINATION_CLIENT_SECRET = 'REPLACE_WITH_DESTINATION_CLIENT_SECRET'

.\Invoke-ContentTransfer.ps1 `
    -ConfigPath .\refresh.json `
    -PollTimeoutSeconds 7200 `
    -StatePath .\journals\refresh-001.json `
    -Verbose

Keep credentials outside the JSON and source control. Relative paths resolve against the current working directory. Use a new journal filename for each run; existing journals are deliberately not overwritten. If -StatePath is omitted, the script creates a unique journal under the system temporary directory.

-PollTimeoutSeconds 7200 allows two hours for each polling operation, such as waiting for an export or import. It does not change the separate HTTP request timeout or set a two-hour limit for the whole execution. -Verbose adds sanitized request and response diagnostics.

The PowerShell entry script and README provide the complete implementation and parameter reference, including troubleshooting and status inspection.

Use the same workflow in Azure DevOps

Running locally is useful while establishing the configuration or investigating a transfer. Once the team needs to refresh environments regularly, a pipeline provides a shared way to execute the operation without relying on someone's workstation or a locally maintained copy of the scripts.

The Azure DevOps YAML supplies that execution wrapper. It checks out the repository, runs the same PowerShell entry script on an agent, passes in the selected configuration and merge-strategy override, injects connection settings, and publishes the execution journal as an artifact. The PowerShell utility still owns the API orchestration; the pipeline provides the execution environment, parameters, logs and retained journal.

I keep this pipeline manually triggered because refreshing content is a deliberate operational decision. A code commit does not tell us that a lower environment is ready to have its content replaced. The team may be in the middle of testing, authors may be preparing new pages, or a refresh may need to happen just before a particular investigation. A manual run lets the operator coordinate the timing, select the scope and choose the merge behavior for that occasion.

Keeping the refresh separate from application deployment also means the team can copy current content without deploying code, or deploy code without refreshing content. The checked-in configuration and pipeline logs make each execution easier to review and investigate afterward.

To adapt it for your project:

  1. Add the scripts and JSON configurations to the repository, update the YAML's configuration choices, and register it as a pipeline.
  2. Configure and authorize its variable group. Supply the source and destination CM URLs and both automation-client credential pairs, mark the client secrets as secret, and map them to the script's environment variables through the YAML's env block.
  3. Select a configuration, choose whether to use its merge strategies or override them, and start the run. The example template fixes production as the source and development as the destination. To target a different lower environment, adapt those variable mappings and labels before registering the pipeline.
  4. Review the logs and download the sitecore-transfer-journal artifact afterward. The artifact step uses condition: always() so it also runs after an ordinary transfer failure, provided the agent remains available.

The template has no commit or pull-request triggers and does not publish content. Its job timeout is separate from the script's polling timeout. The supplied YAML uses the script's default 30-minute polling window; the two-hour setting in the local example is not inherited by the pipeline. Set PollTimeoutSeconds in the YAML's script arguments if needed, and check the agent's available runtime for larger transfers.

Understand completion and failures

Wait for Outcome=Succeeded and exit code 0. The script requires the import to report Finished, the destination blob to report Transferred, and no validation errors before completing cleanup. An HTTP 202 Accepted response means a request was accepted for processing; it does not establish completion. Items appearing in the content tree alone are also insufficient.

If polling times out, the import may still be running inside Sitecore. Closing PowerShell or starting another execution does not cancel it. A new execution creates a new transfer, so inspect the existing operation before retrying. The journal records transfer identifiers, progress, validation errors and cleanup outcomes to support that investigation; it is not an automatic resume mechanism.

Cleanup also does not roll back imported content. If a later stage fails, earlier changes can remain in the destination. The utility preserves destination artifacts when import status is active or uncertain, and a cleanup failure can produce a nonzero exit even after content has imported.

After a successful refresh, check representative pages, shared data sources, images and PDFs. Review any overlap with serialized items so a later deployment does not unexpectedly overwrite refreshed content. Then publish in the lower environment through the normal workflow: the transfer updates master, while publishing and frontend validation remain separate steps.