Public/Restore-WebsiteRoot.ps1

function Restore-WebsiteRoot
{
    ##############################################################################
    #.SYNOPSIS
    # Restores website root files (used with Backup-WebsiteRoot)
    #
    #.DESCRIPTION
    # Use this function to maintain backups restore using Robocopy if deployment has failed
    # Detailed information about the Robocopy exit codes is provided in the end of the operaton
    # Robocopy log file (BACKUP_DIR\_SitecoreDeploymentPS\RobocopyRestoreLog.txt)
    # Reverts all changed files and deletes the newly created ones, except for excluded directories (if any)
    # Used with Backup-WebsiteRoot
    #
    #.PARAMETER SourceDir
    # Root directory of backups. (absolute path)
    #
    #.PARAMETER TargetDir
    # Website root directory (absolute path)
    #
    #.EXAMPLE
    # $sourceDir = "C:\backups"
    # $targetDir = "C:\inetpub\wwwroot\website"
    # Restore-WebsiteRoot -SourceDir $sourceDir -TargetDir $targetDir
    ##############################################################################

    [CmdletBinding()]
    Param
    (
        $VerbosePreference = $PSCmdlet.GetVariableValue('VerbosePreference'),

        [string]$SourceDir,
        [string]$TargetDir
    )

    try 
    {
        #region Begin

        $systemLog = NewSystemLog -Name "Restore-WebsiteRoot"
        WriteLog -Path $systemLog -Message "OUTPUT: Restore files started"

        #endregion Begin

        #region Process

        RestoreWebsiteRoot -SourceDir $SourceDir -TargetDir $TargetDir -LogFile $systemLog

        #endregion Process

        #region End

        ShowRobocopyResultMessage -LogFile $systemLog

        if($LASTEXITCODE -lt 8)
        {
            WriteLog -Path $systemLog -Message "OUTPUT: Restore files finished"
            WriteLog -Path $systemLog -Message "OUTPUT: Detailed information logged into '$systemLog'"
            Exit 0
        }
        else
        {
            Throw "Unexpected 'Robocopy exit code $LASTEXITCODE'. (Success exit codes are all codes between 'Robocopy exit code 0 - Robocopy exit code 7')"
        }

        #endregion End
    }
    catch
    {
        RegisterException
    }
}