# ============================================================================ # Copyright and license info is available in the LICENSE file included with # the Server Deployment Package (SDP), and also available online: # https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE # ---------------------------------------------------------------------------- <# .Synopsis Daily_Backup.ps1 performs journal rotation to offline database and creates offline checkpoint .Description Admin access is required. .Parameter sdp-instance The specified instance to backup .Example daily_backup.ps1 Master .Example daily_backup.ps1 1 #> [CmdletBinding()] param ([string]$SDPInstance = $(throw "SDPInstance parameter is required.")) # Source the SDP Functions shared between scripts $SDPFunctionsPath = Split-Path -parent $MyInvocation.MyCommand.Path | Join-Path -childpath "SDP-Functions.ps1" . $SDPFunctionsPath $global:ScriptName = "Daily-backup.ps1" $global:ScriptTask = "Daily Backup" $global:LogFileName = "checkpoint.log" Parse-SDP-Config-File($MyInvocation.MyCommand.Path) Create-log-file $OrigPath = convert-path . Set-Location -Path $global:LOGS_DIR try { Invoke-P4Login Check-Offline-DB-Exists Ensure-Checkpoint-Not-Running Get-Current-Journal-Counter Get-Offline-Journal-Counter truncate-journal Rotate-Logfiles replay-journals-to-offline-db create-offline-checkpoint #recreate-offline-db-files remove-old-checkpoints-and-journals check-disk-space remove-old-logs log("End $P4SERVER Checkpoint") send-email "${env:computername} ${global:SDP_INSTANCE_P4SERVICE_NAME} ${global:ScriptTask} log." set-counter Signal-Checkpoint-Complete Write-Output "`r`n${global:ScriptTask} completed successfully - see ${global:logfile}" } Catch { $ErrorMessage = $_.Exception.Message $FailedItem = $_.Exception.ItemName Log($error[0]) send-email "FAILED: ${env:computername} ${global:SDP_INSTANCE_P4SERVICE_NAME} ${global:ScriptTask} log." Write-Output "`r`n${global:ScriptTask} FAILED! - see ${global:logfile}" } Set-Location -Path $OrigPath