47 lines
1.5 KiB
PowerShell
47 lines
1.5 KiB
PowerShell
function Backup-AlkamiOrb {
|
|
<#
|
|
.SYNOPSIS
|
|
Compress C:\Orb to C:\tools\Backup folder
|
|
#>
|
|
[CmdletBinding()]
|
|
Param (
|
|
[Parameter(Mandatory=$false)]
|
|
[string]$orbPath,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[string]$backupPath = "c:\Tools\Backups\",
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[int]$cutoffDays = 15
|
|
)
|
|
|
|
$logLead = (Get-LogLeadName);
|
|
$datetime = Get-Date -Format "MM_dd_yyyy_HHmmss"
|
|
$absoluteCutoff = [System.Math]::Abs($cutoffDays)
|
|
$cutoffDate = (Get-Date).AddDays($absoluteCutoff * -1)
|
|
|
|
if([string]::IsNullOrEmpty($orbPath)) {
|
|
$orbPath = (Get-OrbPath)
|
|
}
|
|
|
|
if (!(Test-Path $backupPath)) {
|
|
(New-Item -path $backupPath -ItemType Directory) | Out-Null
|
|
}
|
|
|
|
if (Test-Path $orbPath) {
|
|
try {
|
|
Write-Output ("$logLead : Backup Files from {0} to {1}" -f $orbPath,$backupPath )
|
|
$zipname = "$($backupPath)Orb_$($datetime).zip"
|
|
7z.exe a -tzip -y $zipname $orbPath -snl
|
|
} catch {
|
|
Throw ("$logLead : Archive Failed {0}" -f $zipname )
|
|
} finally {
|
|
Write-Output ("$logLead : Archive Completed {0}" -f $zipname )
|
|
}
|
|
} else {
|
|
Throw ("$logLead : Path not found {0}" -f $orbPath )
|
|
}
|
|
|
|
Write-Output ("$logLead : Deleting Old Backups")
|
|
Get-childitem $backupPath | Where-Object { ! $_.PsIsContainer -and $_ -match '^Orb_.*.zip'}| Where-Object { $_.CreationTimeUtc -lt [System.TimeZoneInfo]::ConvertTimeToUtc($cutOffDate) } | Select-Object -ExpandProperty FullName | Remove-item
|
|
} |