A tool to quickly restore Sitecore instances after reinstalling OS SitecoreHow-To

A solution for restoring Sitecore instances after reinstalling OS

I think every Web developer, who works on a few projects at the same time, knows how difficult it is to make a decision on reinstalling an operating system. You’ll need to reinstall IIS, Application Pools, Sites, host etc. You may suggest that we use backup tools that back up IIS settings before reinstalling and restoring them after the OS is reinstalled. And it works. However, things have become more complicated with Sitecore 9. Along with standard IIS configuration we have at least two windows services to restore after the OS is reinstalled: Sitecore XConnect Search Indexer and Sitecore Marketing Automation Engine. Also, there is Sitecore Processing Engine service since Sitecore 9.1. If you want your Sitecore instance to work correctly after the operating system is reinstalled, you’ll need to ensure that these services are installed and are running, as well as application pool and website in IIS. Don't forget about indexes and databases.

The last time I felt that my OS is dying, I invented a way to restore all my environments. The following steps needed to be done before re-installation:

  1. Make sure that the root folders of website, xconnect and identity server are stored on a drive different from the OS system drive, because the installation drive is usually formatted during OS reinstallation. Good news is that I already have a solution (how to install the Sitecore 9.x in the non-default location). It ensures me that I will not lose my root folders if something happens with the system drive. Otherwise you can copy the content from C:/inetpub/wwwroot to a non-OS drive
  2. Backup sitecore database and store backups on non-OS drive or just leave them as they are if they are not there are already

The steps above have to be done for each website that you are going to restore in the future.

After all preparations are done, you can reinstall your OS. Once it is done, the following module need to be downloaded to help us to recover our instances: Recovery Tool (a source code is available on github).

Archive contains the list of files that represent a configuration for SIF to recovery App_Pools, Websites, Windows Services, Solr cores:

  • xconnect-xp0.json
  • xconnect-solr.json
  • sitecore-XP0.json
  • sitecore-solr.json
  • RecoveryTool.ps1
  • RecoveryTool.json
  • IdentityServer.json
  • createcert.json

Follow the steps below to prepare your environment to install Sitecore instance:

  1. Install MSSQL server. This step is optional and is required in case you use MS SQL server installed on the same machine and it was removed during OS reinstallation;
    Attach or restore all Sitecore databases that you had before;
  2. Install Solr server. This step is optional andis required in case you use Solr server installed on the same machine and it was removed during OS reinstallation; Follow the original Sitecore 9.x installation guide to determine the required Solr version. Solr have to be available via SSL protocol and run as a windows service;
  3. Install the SIF Module using MyGet
    • Open PowerShell as an administrator in Windows OS
    • To register the repository, run the following cmdlet in a PowerShell command line:
      
      Register-PSRepository -Name SitecoreGallery
      -SourceLocation https://sitecore.myget.org/F/sc-powershell/api/v2
    • When prompted to install, press Y, and then press Enter
    • Install the PowerShell module by running the following cmdlet:
      
      Install-Module SitecoreInstallFramework
    • When prompted to install, press Y, and then press Enter.
  4. Open PowerShell as an administrator and navigate to the folder where you have unzipped the package.
  5. Run the following cmdlet to set up prerequisites:
    
    Install-SitecoreConfiguration -Path .\Prerequisites.json

When the installation is complete, you might be informed that a server reboot is required. The steps above are pretty standard and always require for first Sitecore installation.

Follow the steps below to recover your previous Sitecore instance:

  1. Navigate to the folder where you have unzipped the package.
  2. In the folder, edit the RecoveryTool.ps1 script and update
  3. each line with the settings that are appropriate for your environment.
  4. Open PowerShell as an administrator and navigate to the folder where you have unzipped the package.
  5. Run the following cmdlet to recover you instance:
    
    .\RecoveryTool.ps1
  6. Choose “Install” when you are asked.

Once the recovering is finished, you will have your Sitecore instance restored. Recovery Tool does the following:

  • Creates IIS Application Pool;
  • Creates IIS Site;
  • Sets bindings;
  • Updates the hosts file with selected bindings;
  • Sets up and run windows services such as XConnect Search Indexer, Sitecore Marketing Automation Engine and Sitecore Processing Engine;
  • Creates and populates Solr cores.

Also, the tool has the opposite functionality. Let’s say you have a temporary unused Sitecore instance. For example, as a Sitecore developer, I have about eight sitecore instances installed on my machine. But I use regularly only two of them. To save my laptop resources, I want to temporarily remove unused instances. And the tool can help me with that. Follow the steps below:

  1. Navigate to the folder where you have unzipped the package.
  2. In the folder, edit the RecoveryTool.ps1 script and update each line with the settings that are appropriate for your environment.
  3. Open PowerShell as an administrator and navigate to the folder where you have unzipped the package.
  4. Run the following cmdlet to recover you instance:
    
    .\RecoveryTool.ps1
  5. Choose “Uninstall” when you will be asked.

Once the execution is finished, selected Sitecore instance will be removed. Recovery Tool in this mode does the following:

  • Removes IIS Application Pool;
  • Removes IIS Site;
  • Removes bindings;
  • Removes selected bindings from the hosts file;
  • Removes windows services such as XConnect Search Indexer, Sitecore Marketing Automation Engine and Sitecore Processing Engine;
  • Removes Solr cores.

Then, you can easily restore your Sitecore instance using the tool again.

Artsem Prashkovich - Sitecore MVP/ Lead Developer

artem prashkovich

Artsem Prashkovich

Artsem is a Sitecore MVP and Lead developer at Brimit working on Sitecore projects since 2012. Sitecore certified developer. Certified Scrum Master.