Running Database Clean Up Task Manually After Sitecore Upgrade in Docker
Hello everyone, In this blog we will see how we can run database clean up task manaully using Sitecore CLI and why it is important especially during upgrade. Recently, we were working on Sitecore upgrade project from 10.1 to 10.3. Our solution was based on Docker setup. If you go through Sitecore Upgrade guide for container, you will find that Sitecore provide mssql-upgrade docker image which takes care of upgrading the SQL schema and tables required for the required Sitecore version to function properly.But if you closely observe during sql upgrade, you will see Sitecore modules are not updated during the process. Sitecore documentation guide provide information how we can upgrade different Sitecore module which is used in the solution.
In our solution, we were using Sitecore PowerShell and Sitecore SXA module.Also in Sitecore 10.3, Sitecore is providing this module as Item As Resource(.dat files) instead Sitecore Items in the package. So whenever we are upgrading, we need to remove the dependency module items from master and core database, so that it will come through Resource file.To understand more about Item as resource file just check below blog link in reference section.
Lets start with the process
Step 1: To install Sitecore CLI, we first need to install Sitecore Management Service. You can add this module as layer in your CM docker file. Note: Check the compatibility of Sitecore Management service with Sitecore CLI being used
FROM scr.sitecore.com/sxp/modules/sitecore-management-services-xp1-assets:5.2-ltsc2022 AS management_services
# Copy Sitecore Management Services for Sitecore CLI
COPY --from=management_services C:\\module\\cm\\content C:\\inetpub\\wwwroot
Step 2:Create a folder under any drive.Open Windows Powershell in Administrator mode and navigate there.Run the following commands to install Sitecore CLI. Run it one by one
dotnet new tool-manifest
dotnet nuget add source -n Sitecore https://nuget.sitecore.com/resources/v3/index.json
dotnet tool install Sitecore.CLI
Step 3:Once everything is successfull, now initialize the Sitecore using below command from same folder.
dotnet sitecore init
Step 4:After initialization is complete, we need to give access to our Sitecore instance from powershell
dotnet Sitecore login --authority {identity server url} --cm {cmurl} --allow-write true
Step 5: Once authorization is complete, now we need to add the plugin "Sitecore.DevEx.Extensibility.ResourcePackage" through below command if it is not available.
//To check the plugin
dotnet sitecore plugin list
// To add plugin
dotnet Sitecore plugin add -n Sitecore.DevEx.Extensibility.ResourcePackage
Step 6: Now run the clean up task using below command and you see the message of cleanup task for master,web and core database.
dotnet sitecore itemres cleanup --verbose
Note: Please create a list of Module items in and excel file before you run the clean up task which later can be use for verfication that items is coming from resource file or not. Just try to delete items and it will give notifcation that item is coming from resource file and can't be deleted.
Hopefully this will help when you are working on Sitecore upgrade and updating Sitecore Modules.
Thanks for reading and Happy learning !!!
You can check my other blogs too if interested. Blog Website
References:
- https://blog.martinmiles.net/post/everything-you-wanted-to-ask-about-items-as-resources-coming-with-new-sitecore-10-1
- https://doc.sitecore.com/xp/en/developers/103/developer-tools/version-compatibility.html
- https://doc.sitecore.com/xp/en/developers/103/developer-tools/install-sitecore-command-line-interface.html
Comments
Post a Comment