Public/Backup-WebsiteRootRemotely.ps1
function Backup-WebsiteRootRemotely { ############################################################################## #.SYNOPSIS # Backs up website root files remotely (used with Restore-WebsiteRootRemotely) # #.DESCRIPTION # Use this function to maintain backups using Robocopy before starting the deployment # Detailed information about the Robocopy exit codes is provided in the end of the operaton # Robocopy log file (BACKUP_DIR\_SitecoreDeploymentPS\RobocopyBackupLog.txt) # Ability to exclude folders and files from backup # Used with Restore-WebsiteRoot # #.PARAMETER SourceDir # Website root directory (absolute path) # #.PARAMETER TargetDir # Backup target directory (absolute path) # #.PARAMETER ExcludedDirs # [OPTIONAL] Directories and files which won't be backed up (coma separated, absolute paths) # #.PARAMETER ComputerName # Name of the remote computer you will connect to # #.PARAMETER Username # Username # #.PARAMETER Password # Password # #.EXAMPLE # $sourceDir = "C:\inetpub\wwwroot\website" # $targetDir = "C:\backup" # $excludedDirs = "$sourceDir\_DEV, $sourceDir\_CMP, $sourceDir\upload, $sourceDir\temp, $sourceDir\sitecore, $sourceDir\sitecore modules, $sourceDir\sitecore_files" # $computerName = "RemoteComputer" # $username = "username" # $password = "password" # Backup-WebsiteRootRemotely -ComputerName $computerName -Username $username -Password $password -SourceDir $sourceDir -TargetDir $targetDir -ExcludedDirs $excludedDirs ############################################################################## [CmdletBinding()] Param ( $VerbosePreference = $PSCmdlet.GetVariableValue('VerbosePreference'), [string]$SourceDir, [string]$TargetDir, [string]$ExcludedDirs, [string]$ComputerName, [string]$Username, [string]$Password ) try { #region Begin $systemLog = NewSystemLog -Name "Backup-WebsiteRemotely" WriteLog -Path $systemLog -Message "OUTPUT: Starting remoting, please wait" #endregion Begin #region Process $session = NewRemoteSession -ComputerName $ComputerName -Username $Username -Password $Password -LogFile $systemLog WriteLog -Path $systemLog -Message "OUTPUT: Waiting result from remoting, please wait" $capturedResult = Invoke-Command -Session $session -ScriptBlock ${function:BackupWebsiteRootRemotely} -ArgumentList $SourceDir, $TargetDir, $ExcludedDirs, $VerbosePreference foreach ($message in $capturedResult) { WriteLog -Path $systemLog -Message $message } #endregion Process } catch { RegisterException } } |