From 7f9777e0fdd36f32dd354d7e0b98767ef678abf7 Mon Sep 17 00:00:00 2001 From: KavishreeShanmugam11 Date: Thu, 21 Mar 2024 16:52:51 +0530 Subject: [PATCH] Added commandlet to fetch snapshot infromation using v2 api. Included readme doc file for new commandlets. --- .../find-cohesityobjectsnapshot.md | 71 ++++ .../restore-cohesityremoteoracledatabase.md | 374 ++++++++++++++++++ docs/sidebar.md | 2 + .../Cohesity.PowerShell.Core.psd1 | 1 + .../Cohesity.PowerShell.psd1 | 1 + .../Cohesity.format.ps1xml | 65 +++ .../Restore/Find-CohesityObjectSnapshot.ps1 | 58 +++ .../Restore-CohesityRemoteOracleDatabase.ps1 | 98 +++-- 8 files changed, 642 insertions(+), 28 deletions(-) create mode 100644 docs/cmdlets-reference/find-cohesityobjectsnapshot.md create mode 100644 docs/cmdlets-reference/restore-cohesityremoteoracledatabase.md create mode 100644 src/Cohesity.Powershell/Scripts/Restore/Find-CohesityObjectSnapshot.ps1 diff --git a/docs/cmdlets-reference/find-cohesityobjectsnapshot.md b/docs/cmdlets-reference/find-cohesityobjectsnapshot.md new file mode 100644 index 00000000..b85afc99 --- /dev/null +++ b/docs/cmdlets-reference/find-cohesityobjectsnapshot.md @@ -0,0 +1,71 @@ +# Find-CohesityObjectSnapshot + +## SYNOPSIS +List the snapshots for a given object using cohesity v2 REST API. + +## SYNTAX + +``` +Find-CohesityObjectSnapshot [-ObjectId ] [-JobId ] [] +``` + +## EXAMPLES + +### EXAMPLE 1 +``` +Find-CohesityObjectSnapshot -ObjectId 12 +``` + +Returns list of snapshot information of specified object with id 12. + +### EXAMPLE 2 +``` +Find-CohesityObjectSnapshot -ObjectId 12 -JobId 1111:2222:12 +``` + +Returns list of snapshot information of specified object with id 12, which is protected through specified protection job. + +## PARAMETERS + +### -ObjectId +Specifies the id of the Object. + +```yaml +Type: Int64 +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -JobId +List of protection group id. If specified, this returns only the snapshots of the specified object ID, which belong to the provided protection group IDs. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +### Cohesity.Model.ObjectSnapshot +## NOTES + +## RELATED LINKS +[Read More](https://cohesity.github.io/cohesity-powershell-module/#/README) diff --git a/docs/cmdlets-reference/restore-cohesityremoteoracledatabase.md b/docs/cmdlets-reference/restore-cohesityremoteoracledatabase.md new file mode 100644 index 00000000..d29cd9de --- /dev/null +++ b/docs/cmdlets-reference/restore-cohesityremoteoracledatabase.md @@ -0,0 +1,374 @@ +# Restore-CohesityRemoteOracleDatabase + +## SYNOPSIS +Restores the specified oracle database from a remote backup. + +## SYNTAX + +``` +Restore-CohesityRemoteOracleDatabase [[-BCTFilePath] ] [[-DatabaseFileDestination] ] [-EnableArchiveLogMode] [[-DatabaseName] ] [[-JobId] ] [[-NewDatabaseName] ] [-NoFilenameCheck] [[-NumRedoLogGroup] ] [[-NumTempFiles] ] [[-OracleBase] ] [[-OracleHome] ] [[-RedoLogMemberPath] ] [[-RedoLogMemberPrefix] ] [[-RedoLogSizeInMb] ] [[-SnapshotId] ] [[-SourceId] ] [[-TargetSource] ] [[-TargetSourceId] ] [[-TaskName] ] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +Restores the specified oracle database from a remote backup. + +## EXAMPLES + +### EXAMPLE 1 +``` +Restore-CohesityRemoteOracleDatabase -DatabaseName db_1 -SourceId 3 -OracleHome /u01/app/oracle/product/19c/db_1 -OracleBase /u01/app/oracle/product/ -DatabaseFileDestination /u01/app/oracle/product/19c/db_1 -TargetSourceId 1 -JobId 12 -NewDatabaseName new_db1 -RedoLogMemberPath '/' -NoFilenameCheck -EnableArchiveLogMode -NumRedoLogGroup 3 +``` + +Restores the specified oracle database from the remote cluster using latest snapshot, protected by job with id 12, from the source with id 3 to the target oracle source with id 1. With specified restore settings. +To get the source details to be restored, +  $oracleObj = Find-CohesityObjectsForRestore -Environments KOracle +  $DatabaseName = $oracleObj[0].SnapshottedSource.name +  $SourceId = $oracleObj[0].SnapshottedSource.ParentId +To get the target source detail, where database need to be restored, +  $sourceObj = Get-CohesityProtectionSource -Environments kOracle +  $TargetSourceId = $sourceObj[0].protectionSource.id + +### EXAMPLE 2 +``` +Restore-CohesityRemoteOracleDatabase -DatabaseName db_1 -SourceName x.x.x.x -OracleHome /u01/app/oracle/product/19c/db_1 -OracleBase /u01/app/oracle/product/ -DatabaseFileDestination /u01/app/oracle/product/19c/db_1 -TargetSource y.y.y.y -JobId 12 -NewDatabaseName new_db1 -SnapshotId abcd +``` + +Restores the specified oracle database from the remote cluster using specified snapshot, protected by job with id 12, from the source with id 3 to the target oracle source y.y.y.y. With specified restore settings. +To get the snapshot id for restore, +  $snapshotObj = Find-CohesityObjectSnapshot -Object +  $SnapshotId = $snapshotObj[0].id + + +## PARAMETERS + +### -BCTFilePath +Specifies BCT file path. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DatabaseFileDestination +Location to put the database files(datafiles, logfiles etc.). + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -EnableArchiveLogMode +Specifies archive log mode for oracle restore. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DatabaseName +Specifies the job id that backed up this Oracle database. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -JobId +Specifies the job id that backed up this Oracle database. + +```yaml +Type: Int64 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NewDatabaseName +Specifies a new name for the restored database. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoFilenameCheck +Specifies whether to validate filenames or not in Oracle alternate restore workflow. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NumRedoLogGroup +Number of redo log groups. + +```yaml +Type: Long +Parameter Sets: (All) +Aliases: + +Required: False +Position: 6 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NumTempFiles +How many tempfiles to use for the recovered database. + +```yaml +Type: Long +Parameter Sets: (All) +Aliases: + +Required: False +Position: 7 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OracleBase +Specifies the Oracle base directory path. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 8 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OracleHome +Specifies the Oracle home directory path. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 9 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RedoLogMemberPath +List of members of this redo log group. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: 10 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RedoLogMemberPrefix +Log member name prefix. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 12 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RedoLogSizeInMb +Size of the member in MB. + +```yaml +Type: Long +Parameter Sets: (All) +Aliases: + +Required: False +Position: 11 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SnapshotId +Specifies the snapshot id for this Oracle database. If not specified the latest snapshot will be used to restore. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 11 +Default value: Latest Recoverable Snapshot +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SourceId +Specifies id of an oracle source from where database need to be restored. + +```yaml +Type: Long +Parameter Sets: (All) +Aliases: + +Required: True +Position: 13 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TargetSource +Specifies the name of an alternate Oracle source where database to be restored. +This can be obtained using Get-CohesityProtectionSource -Environments kOracle. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 14 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TargetSourceId +Specifies the id of an alternate Oracle source where database to be restored. + +```yaml +Type: Long +Parameter Sets: (All) +Aliases: + +Required: False +Position: 15 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TaskName +Specifies the name of the restore task. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 15 +Default value: "Restore-Oracle-Object-" + (Get-Date -Format "dddd-MM-dd-yyyy-HH-mm-ss").ToString() +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES +Published by Cohesity + +## RELATED LINKS + +[https://cohesity.github.io/cohesity-powershell-module/#/README](https://cohesity.github.io/cohesity-powershell-module/#/README) + diff --git a/docs/sidebar.md b/docs/sidebar.md index b703e162..21252b13 100644 --- a/docs/sidebar.md +++ b/docs/sidebar.md @@ -142,11 +142,13 @@ - **Recovery** - [Find-CohesityFilesForRestore](cmdlets-reference/find-cohesityfilesforrestore.md) - [Find-CohesityFileSnapshot](cmdlets-reference/find-cohesityfilesnapshot.md) +- [Find-CohesityObjectSnapshot](cmdlets-reference/find-cohesityobjectsnapshot.md) - [Find-CohesityRemoteFileSnapshot](cmdlets-reference/find-cohesityremotefilesnapshot.md) - [Find-CohesityObjectsForRestore](cmdlets-reference/find-cohesityobjectsforrestore.md) - [Restore-CohesityMSSQLObject](cmdlets-reference/restore-cohesitymssqlobject.md) - [Restore-CohesityOracleDatabase](cmdlets-reference/restore-cohesityoracledatabase.md) - [Restore-CohesityRemoteMSSQLObject](cmdlets-reference/restore-cohesityremotemssqlobject.md) +- [Restore-CohesityRemoteOracleDatabase](cmdlets-reference/restore-cohesityremoteoracledatabase.md) - [Restore-CohesityVMwareVM](cmdlets-reference/restore-cohesityvmwarevm.md) - [Restore-CohesityHyperVVM](cmdlets-reference/restore-cohesityhypervvm.md) - [Restore-CohesityAcropolisVM](cmdlets-reference/restore-cohesityacropolisvm.md) diff --git a/src/Cohesity.Powershell/Cohesity.PowerShell.Core.psd1 b/src/Cohesity.Powershell/Cohesity.PowerShell.Core.psd1 index c8b0acad..09cb3a4e 100644 --- a/src/Cohesity.Powershell/Cohesity.PowerShell.Core.psd1 +++ b/src/Cohesity.Powershell/Cohesity.PowerShell.Core.psd1 @@ -76,6 +76,7 @@ FunctionsToExport = @( 'Copy-CohesityView', 'Copy-CohesityVMwareVM', 'Find-CohesityFileSnapshot', + 'Find-CohesityObjectSnapshot', 'Find-CohesityRemoteFileSnapshot', 'Get-CohesityActiveDirectory', 'Get-CohesityCmdletConfig', diff --git a/src/Cohesity.Powershell/Cohesity.PowerShell.psd1 b/src/Cohesity.Powershell/Cohesity.PowerShell.psd1 index 70bbe537..74f81ca8 100644 --- a/src/Cohesity.Powershell/Cohesity.PowerShell.psd1 +++ b/src/Cohesity.Powershell/Cohesity.PowerShell.psd1 @@ -76,6 +76,7 @@ FunctionsToExport = @( 'Copy-CohesityView', 'Copy-CohesityVMwareVM', 'Find-CohesityFileSnapshot', + 'Find-CohesityObjectSnapshot', 'Find-CohesityRemoteFileSnapshot', 'Get-CohesityActiveDirectory', 'Get-CohesityCmdletConfig', diff --git a/src/Cohesity.Powershell/Cohesity.format.ps1xml b/src/Cohesity.Powershell/Cohesity.format.ps1xml index 68fbd141..d6e88945 100644 --- a/src/Cohesity.Powershell/Cohesity.format.ps1xml +++ b/src/Cohesity.Powershell/Cohesity.format.ps1xml @@ -1794,6 +1794,71 @@ + + + System.Object.ObjectSnapshot.TableView + + System.Object#ObjectSnapshot + + + + + + + $_.SnapshotTimestampUsecs | Convert-CohesityUsecsToDateTime + + + $_.ObjectName + + + $_.ObjectId + + + $_.Environment + + + $_.SnapshotTargetType + + + $_.RunType + + + $_.ProtectionGroupName + + + $_.Id + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + System.Object.ProtectionPolicy.TableView diff --git a/src/Cohesity.Powershell/Scripts/Restore/Find-CohesityObjectSnapshot.ps1 b/src/Cohesity.Powershell/Scripts/Restore/Find-CohesityObjectSnapshot.ps1 new file mode 100644 index 00000000..1db5a12c --- /dev/null +++ b/src/Cohesity.Powershell/Scripts/Restore/Find-CohesityObjectSnapshot.ps1 @@ -0,0 +1,58 @@ +function Find-CohesityObjectSnapshot { + <# + .SYNOPSIS + List the snapshots for a given object. + .DESCRIPTION + List the snapshots for a given object. + .NOTES + Published by Cohesity + .LINK + https://cohesity.github.io/cohesity-powershell-module/#/README + .EXAMPLE + Find-CohesityObjectSnapshot -ObjectId 12 + Returns list of snapshot information of specified object with id 12. + .EXAMPLE + Find-CohesityObjectSnapshot -ObjectId 12 -ProtectionGroupIds 1111:2222:12 + Returns list of snapshot information of specified object with id 12, which is protected through specified protection job. + #> + + [OutputType('System.Array')] + [CmdletBinding()] + Param( + # Specifies the id of the Object. + [Parameter(Mandatory = $true)] + [string]$ObjectId, + # List of protection group id. If specified, this returns only the snapshots of the specified object ID, which belong to the provided protection group IDs. + [Parameter(Mandatory = $false)] + [string[]]$ProtectionGroupIds + ) + Begin { + } + + Process { + $snapshotURL = '/v2/data-protect/objects/' + $ObjectId + '/snapshots' + + $filter = "" + if ($JobId) { + if ($filter -ne "") { + $filter += "&" + } + $filter += "protectionGroupIds=$ProtectionGroupIds" + } + + if ($filter -ne "") { + $snapshotURL += "?" + $filter + } + + $snapshotResp = Invoke-RestApi -Method Get -Uri $snapshotURL + + if ($snapshotResp -and $snapshotResp.snapshots) { + $snapshotObj = $snapshotResp.snapshots + # tagging reponse for display format ( configured in Cohesity.format.ps1xml ) + @($snapshotObj | Add-Member -TypeName 'System.Object#ObjectSnapshot' -PassThru) + } + } + + End { + } +} \ No newline at end of file diff --git a/src/Cohesity.Powershell/Scripts/Restore/Restore-CohesityRemoteOracleDatabase.ps1 b/src/Cohesity.Powershell/Scripts/Restore/Restore-CohesityRemoteOracleDatabase.ps1 index d5c2f800..9340325c 100644 --- a/src/Cohesity.Powershell/Scripts/Restore/Restore-CohesityRemoteOracleDatabase.ps1 +++ b/src/Cohesity.Powershell/Scripts/Restore/Restore-CohesityRemoteOracleDatabase.ps1 @@ -1,29 +1,42 @@ function Restore-CohesityRemoteOracleDatabase { <# .SYNOPSIS - Restores the specified files or folders from a remote backup. + Restores the specified oracle database from a remote backup. .DESCRIPTION - Restores the specified files or folders from a remote backup. This commandlet supports only source with environment type VMware/Physical/Isilon. + Restores the specified oracle database from a remote backup. .NOTES Published by Cohesity. .LINK https://cohesity.github.io/cohesity-powershell-module/#/README .EXAMPLE - Restore-CohesityRemoteOracleDatabase -TaskName "Restore-Oracle-Object" -FileName /C/data/file.txt -JobId 1234 -SourceId 843 -TargetSourceId 856 -RestoreMethod AutoDeploy -TargetVMCredential (Get-Credential) - Restores the specified file/folder to the target VM with specified source id from the latest external target backup. + Restore-CohesityRemoteOracleDatabase -DatabaseName db_1 -SourceId 3 -OracleHome /u01/app/oracle/product/19c/db_1 -OracleBase /u01/app/oracle/product/ -DatabaseFileDestination /u01/app/oracle/product/19c/db_1 -TargetSourceId 1 -JobId 12 -NewDatabaseName new_db1 -RedoLogMemberPath '/' -NoFilenameCheck -EnableArchiveLogMode -NumRedoLogGroup 3 + Restores the specified oracle database from the remote cluster using latest snapshot, protected by job with id 12, from the source with id 3 to the target oracle source with id 1. With specified restore settings. + To get the source details to be restored, + $oracleObj = Find-CohesityObjectsForRestore -Environments KOracle + $DatabaseName = $oracleObj[0].SnapshottedSource.name + $SourceId = $oracleObj[0].SnapshottedSource.ParentId + To get the target source detail, where database need to be restored, + $sourceObj = Get-CohesityProtectionSource -Environments kOracle + $TargetSourceId = $sourceObj[0].protectionSource.id .EXAMPLE - Restore-CohesityRemoteOracleDatabase -FileName "/C/myFolder" -NewBaseDirectory "C:\temp\restore" -JobId 61592 -SourceId 3517 - Restores the specified file/folder in the same server from the latest external target backup. - .EXAMPLE - Restore-CohesityRemoteOracleDatabase -FileName "/C/myFolder" -NewBaseDirectory "C:\temp\restore" -JobId 61592 -SourceId 3517 -SnapshotId "exchjik" - Restores the specified file/folder in the same server from the specified external target backup. + Restore-CohesityRemoteOracleDatabase -DatabaseName db_1 -SourceName x.x.x.x -OracleHome /u01/app/oracle/product/19c/db_1 -OracleBase /u01/app/oracle/product/ -DatabaseFileDestination /u01/app/oracle/product/19c/db_1 -TargetSource y.y.y.y -JobId 12 -NewDatabaseName new_db1 -SnapshotId abcd + Restores the specified oracle database from the remote cluster using specified snapshot, protected by job with id 12, from the source with id 3 to the target oracle source y.y.y.y. With specified restore settings. + To get the snapshot id for restore, + $snapshotObj = Find-CohesityObjectSnapshot -Object + $SnapshotId = $snapshotObj[0].id #> [CmdletBinding(DefaultParameterSetName = "Default", SupportsShouldProcess = $True, ConfirmImpact = "High")] Param( + # Specifies BCT file path. + [Parameter(Mandatory = $false)] + [string]$BCTFilePath, # Location to put the database files(datafiles, logfiles etc.). [Parameter(Mandatory = $true)] [string]$DatabaseFileDestination, + # Specifies archive log mode for oracle restore. + [Parameter(Mandatory = $false)] + [switch]$EnableArchiveLogMode, # Specifies name of the database to recover. [Parameter(Mandatory = $true)] [string]$DatabaseName, @@ -32,8 +45,11 @@ function Restore-CohesityRemoteOracleDatabase { [ValidateRange(1, [long]::MaxValue)] [long]$JobId, # Specifies a new name for the restored database. - [Parameter(Mandatory = $false)] + [Parameter(Mandatory = $true)] [string]$NewDatabaseName, + # Specifies whether to validate filenames or not in Oracle alternate restore workflow. + [Parameter(Mandatory = $false)] + [switch]$NoFilenameCheck, # Number of redo log groups. [Parameter(Mandatory = $false)] [ValidateRange(2, [long]::MaxValue)] @@ -60,13 +76,15 @@ function Restore-CohesityRemoteOracleDatabase { [long]$RedoLogSizeInMb, # Specifies the snapshot id for this Oracle database. If not specified the latest snapshot will be used to restore. [Parameter(Mandatory = $false)] - [ValidateRange(1, [long]::MaxValue)] - [long]$SnapshotId, - # Specifies name of an oracle source. + [string]$SnapshotId, + # Specifies id of an oracle source from where database need to be restored. [Parameter(Mandatory = $true)] - [string]$SourceName, + [long]$SourceId, + # Specifies the name of an alternate Oracle source where database to be restored. + [Parameter(Mandatory = $false)] + [string]$TargetSource, # Specifies the id of an alternate Oracle source where database to be restored. - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $false)] [long]$TargetSourceId, # Specifies the name of the restore task. [Parameter(Mandatory = $false)] @@ -98,21 +116,44 @@ function Restore-CohesityRemoteOracleDatabase { $searchUrl = "/v2/data-protect/search/protected-objects?environments=kOracle&snapshotActions=RecoverApps&searchString=${DatabaseName}&protectionGroupIds=${protectionGroupId}" $searchResult = Invoke-RestApi -Method Get -Uri $searchUrl - $searchObj = $searchResult.objects | Where-Object { $_.name -eq $DatabaseName -and $_.oracleParams.hostInfo.name -eq $SourceName } + $searchObj = $searchResult.objects | Where-Object { $_.name -eq $DatabaseName -and $_.sourceId -eq $SourceId } if (!$searchObj) { - $errorMsg = "Oracle Database '${DatabaseName}' not found in specified protection group." + $errorMsg = "Oracle Database '${DatabaseName}' under source with an id $SourceId is not found in the specified protection group." Write-Output $errorMsg CSLog -Message $errorMsg return } + # Validate provided target oracle source exists. + if ($TargetSource) { + # Find the Id of specified target source + $protectionSources = Get-CohesityProtectionSource -Environments KOracle + foreach ($record in $protectionSources) { + if ($record.protectionSource.Name -eq $TargetSource) { + $TargetSourceId = $record.protectionSource.id + break; + } + } + } elseif ($TargetSourceId){ + $protectionSourceObject = Get-CohesityProtectionSource -Id $TargetSourceId + if ($protectionSourceObject.id -ne $TargetSourceId) { + Write-Output "Cannot proceed, the target oracle source id '$TargetSourceId' is invalid" + return + } + } + + if (!$TargetSourceId){ + Write-Output "Please provide the valid target oracle source." + return + } + <# Check if snapshot detail is provided. If not, collect the latest recoverable job run information. #> - if ($null -eq $SnapshotId) { - $databaseName = $searchObj.name + if (-not $SnapshotId) { + Write-Host "Fetching latest snapshot for restore." $snapshotInfo = $searchObj.latestSnapshotsInfo if ($snapshotInfo -and $snapshotInfo.Length -ne 0) { $snapshotObj = $snapshotInfo[0].localSnapshotInfo @@ -121,14 +162,14 @@ function Restore-CohesityRemoteOracleDatabase { $SnapshotId = $snapshotObj.snapshotId } else { - $errorMsg = "Could not fetch remote snapshot information for the database '$databaseName'" + $errorMsg = "Could not fetch remote snapshot information for the database '$DatabaseName'" Write-Output $errorMsg CSLog -Message $errorMsg -Severity 2 return } } else { - $errorMsg = "Could not fetch remote snapshot information for the database '$databaseName'" + $errorMsg = "Could not fetch remote snapshot information for the database '$DatabaseName'" Write-Output $errorMsg CSLog -Message $errorMsg -Severity 2 return @@ -158,18 +199,19 @@ function Restore-CohesityRemoteOracleDatabase { }; recoveryTarget = 'RecoverDatabase'; recoverDatabaseParams = @{ - bctFilePath = $BCTFilePath; + bctFilePath = if ($BCTFilePath) { $BCTFilePath } else { $null }; databaseName = $NewDatabaseName; dbFilesDestination = if ($DatabaseFileDestination) { $DatabaseFileDestination } else { $OracleHome } - enableArchiveLogMode = $true; - numTempfiles = $NumTempFiles; + enableArchiveLogMode = $EnableArchiveLogMode.IsPresent; + nofilenameCheck = $NoFilenameCheck.IsPresent; + numTempfiles = if ($NumTempFiles) { $NumTempFiles } else { $null }; oracleBaseFolder = $OracleBase; oracleHomeFolder = $OracleHome; - redoLogConf = @{ - groupMemberVec = @($RedoLogMemberPath) - memberPrefix = $RedoLogMemberPrefix + redoLogConfig = @{ + groupMembers = @($RedoLogMemberPath) + memberPrefix = if ($RedoLogMemberPrefix) { $RedoLogMemberPrefix } else { $null }; numGroups = $NumRedoLogGroup - sizeMb = if ($RedoLogSizeInMb) { $RedoLogSizeInMb } else { 20 } + sizeMBytes = if ($RedoLogSizeInMb) { $RedoLogSizeInMb } else { 20 } } } }