Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sitecore Content Transfer Script

Caution

Use at your own discretion. This code is not fully tested and is provided as-is. Review and validate all scripts before running them in any environment.

Moves Sitecore content between environments using the Content Transfer API (source) and the Item Transfer API (destination).


Prerequisites

  • PowerShell 5.1 or later
  • Organization Admin or Organization Owner role in the Sitecore Cloud Portal
  • Automation client credentials for both the source and destination environments

Setup

Step 1 — Create automation client credentials

Repeat the following for each environment (source and destination):

  1. In the Sitecore Cloud Portal, open SitecoreAI Deploy.
  2. Go to Credentials → Environment → Create credentials → Automation.
  3. Fill in the client details and click Create.
  4. Copy the Client ID and Client Secret — they are shown only once.

Step 2 — Configure transferitems.json

Edit transferitems.json to list the Sitecore items you want to transfer. Each entry in DataTrees is one item path with its own scope and merge strategy.

{
  "Database": "master",
  "DataTrees": [
    {
      "ItemPath"     : "/sitecore/content/Home",
      "Scope"        : "ItemAndDescendants",
      "MergeStrategy": "OverrideExistingItem"
    },
    {
      "ItemPath"     : "/sitecore/media library/Project/banner",
      "Scope"        : "SingleItem",
      "MergeStrategy": "KeepExistingItem"
    }
  ]
}

Field reference

Field Required Values
Database Yes "master" | "web"
ItemPath Yes Full Sitecore item path
Scope Yes "SingleItem" — transfer only this item
"ItemAndDescendants" — transfer item and all children
MergeStrategy Yes "OverrideExistingItem" — overwrite matching items in destination
"KeepExistingItem" — skip items that already exist
"OverrideExistingTree" — overwrite the entire subtree
"LatestWin" — keep whichever version is newer

Step 3 — Set environment variables

Set your credentials in the current PowerShell session before running the script:

$env:SITECORE_SRC_CLIENT_ID      = "source-client-id-xxxx"
$env:SITECORE_SRC_CLIENT_SECRET  = "source-client-secret-xxxx"
$env:SITECORE_DEST_CLIENT_ID     = "destination-client-id-yyyy"
$env:SITECORE_DEST_CLIENT_SECRET = "destination-client-secret-yyyy"

The environment host name can be found in
SitecoreAI Deploy → Projects → your project → Authoring environments → your environment → Details → Environment host name


Running the script

.\Move-SitecoreContent.ps1 `
    -SourceBaseUrl      "https://xmc-yourproject-source.sitecorecloud.io" `
    -DestinationBaseUrl "https://xmc-yourproject-dest.sitecorecloud.io"   `
    -ConfigFile         .\transferitems.json

Parameters

Parameter Required Default Description
-SourceBaseUrl Yes Host URL of the source environment
-DestinationBaseUrl Yes Host URL of the destination environment
-ConfigFile No .\transferitems.json Path to the transfer configuration file
-PollIntervalSeconds No 5 Seconds between status poll requests
-TimeoutMinutes No 20 Max total time before the script aborts
-LogFolder No .\logs Folder where timestamped log files are written

What the script does

Source environment                        Destination environment
──────────────────                        ───────────────────────
POST /transfers          ──create──>
GET  /transfers/{id}/status  <──poll──
GET  .../chunks/{n}      ──stream──>      PUT  .../chunks/{n}
                                          POST .../chunksets/{id}/complete  →  .raif file
DELETE /transfers/{id}   ──cleanup──>
                                          POST /ItemsTransfer/...sources    (consume .raif)
                                          GET  /ItemsTransfer/transfers/{id}  <──poll──
  1. Creates a Content Transfer operation on the source for all DataTrees in one API call.
  2. Polls until the operation reaches Completed state.
  3. Streams each encrypted/compressed chunk from source → destination.
  4. Completes each chunk set, producing a .raif file on the destination.
  5. Deletes the transfer from the source (cleanup).
  6. Triggers Item Transfer on the destination to consume each .raif into the database.
  7. Polls until each Item Transfer reaches Finished state.

Output

A timestamped log file is written to .\logs\content-transfer_<yyyyMMdd_HHmmss>.log.

The final lines of the log show a per-RAIF summary:

[OK]   contentTransfer-<uuid>.raif
       State=Finished  Items=34/34  Strategy=OverrideExistingItem
       Id=consumed.20260709...  DB=master  Consumed=2026-07-09T...

=== Migration complete in 60.8s ===

[OK] = Finished · [FAIL] = Failed or Discarded


Files

File Description
Move-SitecoreContent.ps1 Main transfer script
transferitems.json List of items to transfer (edit before each run)
logs/ Timestamped log files from each run

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages