Migrate Content Between XM Cloud Environment
Hello everyone. In this blog we will discuss how we can migrate content between two different XM Cloud environment. As we all know, how important it is to keep the content sync from production to lower environment. It helps to lower down the risk of error in production as testing can be done more efficiently.
In traditional CMS, database restore was one of the most popular way to sync content between environments. But when we are working in XM Cloud, as we all know Its SAAS product, there we don't have control over Databases.
So, how we can restore the content on lower environment in such cases?
The answer is simple, through package migration. Correct?
Nope, package migration is good option when we have very less content and the biggest problem is with media items.
Let's see, how Sitecore Serilization helps in this process to resolve our error. We will use Sitecore CLI commands for our rescue.
Step 1: Setting up the Sitecore Serialization.
- Create a separate folder under C drive called Serialization.
- Copy .config folder, .sitecore folder and sitecore.json file from your docker instance under src-->your solution folder to Serialization folder as created above.
- Open Serialzation folder and check the .config folder having dotnet-tools.json file. Once completed verification just run dotnet tool restore command. This will install all necessary packages to run the Sitecore Serialization.
- Run dotent sitecore or dotnet sitecore --version to verify everything is installed properly.
Step 2: Creating Module.json file to pull the required content. We will create module.json file called HomeContent
{
"namespace": "Project.HomeContent.module.json",
"items": {
"includes": [
{
"name": "Home Content",
"path": "{path of your home page}",
"allowedPushOperations": "CreateAndUpdate",
"scope": "ItemAndDescendants"
}
]
}
}
Step 3: Connecting to your remote environment from where we want the data.
//login to XM Cloud
dotnet sitecore cloud login --client-credentials --client-id {client id of the environment} --client-secret {client secret of the environment} --allow-write
//Connecting to specific environment
dotnet sitecore cloud environment connect --environment-id {environment id} --allow-write
You can check my blog, how to create client id and secrent in XM Cloud by checking the initial steps. Here
Step 4: Pulling the data using Sitecore CLI commands.
//Watch command with sitecore serialization pull will let you know what is going to change but will not update anything
dotnet sitecore ser pull -w -i "Project.HomeContent.module.json" -n "{environment name}"
//Running Specific Module JSON file command to get the data
dotnet sitecore ser pull -i "Project.HomeContent.module.json" -n "{environment name}"
Step 5: Pushing the data using Sitecore CLI commands. Here, I am pushing the changes to my local environment.
//Local XM cloud login
dotnet sitecore cloud login
//sitecore serialization push
dotnet sitecore ser push
If you want to push the changes to any other xm cloud instance, open another windows powershell in admin mode. navigate to the folder and connect to the required environment as shown in step 4. Then run the command dotnet sitecore ser push -w -i "Project.HomeContent.module.json" -n "{environment name}"
//sitecore serialization push will let you know what changes will be pushed without actually changing anything.
dotnet sitecore ser push -w -i "Project.HomeContent.module.json" -n "{environment name}"
//Push command to push the data
dotnet sitecore ser push -n "{environment name}"
If any issue you are getting you can use below command for fixing it.
//Validate command to fix the data
dotnet sitecore ser validate --fix
Verify your changes and you are good to go. Thanks for reading.
References:
- https://www.studert.com/sync-content-between-xm-cloud-environments-automatically
- https://doc.sitecore.com/xp/en/developers/101/developer-tools/the-cli-serialization-command.html#subcommands
You can check my other blogs too if interested. Blog Website
Comments
Post a Comment