109 lines
3.6 KiB
PowerShell
109 lines
3.6 KiB
PowerShell
##########################################################################
|
|
#
|
|
# On Demand Snapshot for all Oracle DBs with a specific SLA
|
|
# Created by Rubrik PS for McDermott, September 2025
|
|
#
|
|
# Must be run with a Global service account.
|
|
#
|
|
# Requires RubrikSecurityCloud module to be installed and working with
|
|
# a Global Service Account with the following rights:
|
|
#
|
|
# - Data Management / Oracle / On-Demand Snapshot
|
|
# - Data Management / SLAs / Both Source and Target SLAs
|
|
#
|
|
# Create the service account file with:
|
|
# Set-RscServiceAccountFile sa.json -OutputFilePath Global.xml
|
|
#
|
|
# Example invocation
|
|
# .\monthlySnap.ps1 -sourceSla "Prod Oracle SLA" -triggerSla "Oracle Monthly Only"
|
|
#
|
|
# v0.1 Initial Release
|
|
#
|
|
##########################################################################
|
|
|
|
param (
|
|
[Parameter(Mandatory=$True,
|
|
HelpMessage="Name of SLA to query")]
|
|
[string]$sourceSla,
|
|
|
|
[Parameter(Mandatory=$True,
|
|
HelpMessage="Name of SLA to trigger")]
|
|
[string]$triggerSla,
|
|
|
|
[Parameter(Mandatory=$False,
|
|
HelpMessage="If set, only print objects that would be backed up")]
|
|
[switch]$dryrun
|
|
)
|
|
|
|
# SA File must be an absolute path
|
|
$GlobalSAFile = "C:\Rubrik\rscSa.xml"
|
|
$logFile = "C:\Rubrik\monthlySnap.log"
|
|
|
|
###########################
|
|
# Script begins
|
|
###########################
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
function Write-Log($message) {
|
|
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
|
$logEntry = "$timestamp $message"
|
|
Add-Content -Path "C:\Rubrik\monthlySnap.log" -Value $logEntry
|
|
Write-Host $logEntry
|
|
}
|
|
|
|
Import-Module RubrikSecurityCloud
|
|
|
|
Connect-Rsc -ServiceAccountFile $GlobalSAFile
|
|
|
|
Write-Log "Connected to Rubrik Security Cloud."
|
|
|
|
$srcSla = Get-RscSla -Name $sourceSla
|
|
if (-not $srcSla) {
|
|
Write-Log "ERROR: No SLA found with name '$sourceSla'. Exiting script."
|
|
Disconnect-Rsc
|
|
exit 1
|
|
}
|
|
Write-Log "Found SLA: $($srcSla.Name) ($($srcSla.Id))"
|
|
|
|
$monthlySla = Get-RscSla -Name $triggerSla
|
|
if (-not $monthlySla) {
|
|
Write-Log "ERROR: No monthly SLA found with name '$triggerSla'. Exiting script."
|
|
Disconnect-Rsc
|
|
exit 1
|
|
}
|
|
Write-Log "Found monthly SLA: $($monthlySla.Name) ($($monthlySla.Id))"
|
|
|
|
$query = New-RscQuery -GqlQuery protectedObjectsConnection
|
|
$query.Var.slaIds = @($srcSla.Id)
|
|
$query.var.filter = @(Get-RscType -Name Filter)
|
|
$query.var.filter[0].field = "IS_RELIC"
|
|
$query.var.filter[0].Texts = "false"
|
|
|
|
$protectedObjects = $query.invoke()
|
|
|
|
Write-Log "INFO: Printing protected objects:"
|
|
$protectedObjects.Nodes | ForEach-Object { Write-Log "Name: $($_.Name), Id: $($_.Id)" }
|
|
|
|
if ($dryrun) {
|
|
Write-Log "Dry run mode: No backups will be triggered. The following objects would have been backed up:"
|
|
$protectedObjects.Nodes | ForEach-Object { Write-Log "[DRYRUN] Name: $($_.Name), Id: $($_.Id)" }
|
|
} else {
|
|
$protectedObjects.Nodes | ForEach-Object {
|
|
Write-Log "Triggering Backup for Name: $($_.Name), Id: $($_.Id)"
|
|
$query = New-RscMutation -GqlMutation takeOnDemandOracleDatabaseSnapshot
|
|
$query.Var.input = Get-RscType -Name TakeOnDemandOracleDatabaseSnapshotInput -InitialProperties config.baseOnDemandSnapshotConfig
|
|
$query.Var.input.id = $_.Id
|
|
$query.Var.input.Config.forceFullSnapshot = $false
|
|
$query.Var.input.Config.baseOnDemandSnapshotConfig.slaId = $monthlySla.id
|
|
$query.Field = Get-RscType -Name AsyncRequestStatus -InitialProperties id
|
|
$result = $query.Invoke()
|
|
if ($result -and $result.Id) {
|
|
Write-Log "Backup triggered for Name: $($_.Name), Job ID: $($result.Id)"
|
|
} else {
|
|
Write-Log "Backup triggered for Name: $($_.Name), but no Job ID returned."
|
|
}
|
|
}
|
|
}
|
|
|
|
Disconnect-Rsc |