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 65c500f8..09cb3a4e 100644 --- a/src/Cohesity.Powershell/Cohesity.PowerShell.Core.psd1 +++ b/src/Cohesity.Powershell/Cohesity.PowerShell.Core.psd1 @@ -8,7 +8,7 @@ RootModule = 'Cohesity.PowerShell.Core.dll' # Version number of this module. -ModuleVersion = '1.9.6' +ModuleVersion = '1.9.8' # Supported PSEditions # CompatiblePSEditions = @() @@ -76,6 +76,7 @@ FunctionsToExport = @( 'Copy-CohesityView', 'Copy-CohesityVMwareVM', 'Find-CohesityFileSnapshot', + 'Find-CohesityObjectSnapshot', 'Find-CohesityRemoteFileSnapshot', 'Get-CohesityActiveDirectory', 'Get-CohesityCmdletConfig', @@ -133,10 +134,11 @@ FunctionsToExport = @( 'Remove-CohesityVlan', 'Restore-CohesityBackupToView', 'Restore-CohesityFileV2', + 'Restore-CohesityOracleDatabase', 'Restore-CohesityRemoteFile', 'Restore-CohesityRemoteFileV2', - 'Restore-CohesityOracleDatabase', 'Restore-CohesityRemoteMSSQLObject', + 'Restore-CohesityRemoteOracleDatabase', 'Restore-CohesityVMwareVM', 'Save-CohesityFile', 'Set-CohesityAlertResolutions', diff --git a/src/Cohesity.Powershell/Cohesity.PowerShell.psd1 b/src/Cohesity.Powershell/Cohesity.PowerShell.psd1 index 507d3a1c..74f81ca8 100644 --- a/src/Cohesity.Powershell/Cohesity.PowerShell.psd1 +++ b/src/Cohesity.Powershell/Cohesity.PowerShell.psd1 @@ -8,7 +8,7 @@ RootModule = 'Cohesity.PowerShell.dll' # Version number of this module. -ModuleVersion = '1.9.6' +ModuleVersion = '1.9.8' # Supported PSEditions # CompatiblePSEditions = @() @@ -76,6 +76,7 @@ FunctionsToExport = @( 'Copy-CohesityView', 'Copy-CohesityVMwareVM', 'Find-CohesityFileSnapshot', + 'Find-CohesityObjectSnapshot', 'Find-CohesityRemoteFileSnapshot', 'Get-CohesityActiveDirectory', 'Get-CohesityCmdletConfig', @@ -132,11 +133,12 @@ FunctionsToExport = @( 'Remove-CohesityVirtualIP', 'Remove-CohesityVlan', 'Restore-CohesityBackupToView', - 'Restore-CohesityFileV2', + 'Restore-CohesityFileV2', + 'Restore-CohesityOracleDatabase', 'Restore-CohesityRemoteFile', 'Restore-CohesityRemoteFileV2', 'Restore-CohesityRemoteMSSQLObject', - 'Restore-CohesityOracleDatabase', + 'Restore-CohesityRemoteOracleDatabase', 'Restore-CohesityVMwareVM', 'Save-CohesityFile', 'Set-CohesityAlertResolutions', @@ -154,7 +156,7 @@ FunctionsToExport = @( 'Update-CohesityProtectionJobRun', 'Update-CohesityUserGroup', 'Update-CohesityVlan' - ) + ) # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @('Add-CohesityViewShare', 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 new file mode 100644 index 00000000..9340325c --- /dev/null +++ b/src/Cohesity.Powershell/Scripts/Restore/Restore-CohesityRemoteOracleDatabase.ps1 @@ -0,0 +1,236 @@ +function Restore-CohesityRemoteOracleDatabase { + <# + .SYNOPSIS + Restores the specified oracle database from a remote backup. + .DESCRIPTION + 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 -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 -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, + # Specifies the job id that backed up this Oracle database. + [Parameter(Mandatory = $true)] + [ValidateRange(1, [long]::MaxValue)] + [long]$JobId, + # Specifies a new name for the restored database. + [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)] + [long]$NumRedoLogGroup, + # Specifies no. of tempfiles to be used for the recovered database. + [Parameter(Mandatory = $false)] + [ValidateRange(1, [long]::MaxValue)] + [long]$NumTempFiles, + # Specifies the Oracle base directory path. + [Parameter(Mandatory = $true)] + [string]$OracleBase, + # Specifies the Oracle home directory path. + [Parameter(Mandatory = $true)] + [string]$OracleHome, + # List of members of this redo log group. + [Parameter(Mandatory = $false)] + [string[]]$RedoLogMemberPath, + # Log member name prefix. + [Parameter(Mandatory = $false)] + [string]$RedoLogMemberPrefix, + # Size of the member in MB. + [Parameter(Mandatory = $false)] + [ValidateRange(1, [long]::MaxValue)] + [long]$RedoLogSizeInMb, + # Specifies the snapshot id for this Oracle database. If not specified the latest snapshot will be used to restore. + [Parameter(Mandatory = $false)] + [string]$SnapshotId, + # Specifies id of an oracle source from where database need to be restored. + [Parameter(Mandatory = $true)] + [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 = $false)] + [long]$TargetSourceId, + # Specifies the name of the restore task. + [Parameter(Mandatory = $false)] + [string]$TaskName = "Recover_Oracle_" + (Get-Date -Format "MMM_dd_yyyy_h_mm_tt").ToString() + ) + Begin { + } + + Process { + # Construct v2 protection group id from provided v1 protection group id + $clusterURL = '/v2/clusters' + $clusterResult = Invoke-RestApi -Method Get -Uri $clusterURL + $clusterId = $clusterResult.id + $clusterIncarnationId = $clusterResult.incarnationId + $protectionGroupId = "${clusterId}:${clusterIncarnationId}:${jobId}" + + # Check whether specified job is valid or not + $protectionGroupUrl = "/v2/data-protect/protection-groups?ids=${protectionGroupId}" + $protectionGroupObj = Invoke-RestApi -Method Get -Uri $protectionGroupUrl + if (-not $protectionGroupObj.protectionGroups) { + $errorMsg = "Cannot proceed, the protection job with id '$JobId' is not found." + Write-Output $errorMsg + CSLog -Message $errorMsg -Severity 2 + return + } + $protectionGroup = $protectionGroupObj.protectionGroups[0] + + # Validate provided oracle database exists + $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 $_.sourceId -eq $SourceId } + + if (!$searchObj) { + $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 (-not $SnapshotId) { + Write-Host "Fetching latest snapshot for restore." + $snapshotInfo = $searchObj.latestSnapshotsInfo + if ($snapshotInfo -and $snapshotInfo.Length -ne 0) { + $snapshotObj = $snapshotInfo[0].localSnapshotInfo + + if ($snapshotObj) { + $SnapshotId = $snapshotObj.snapshotId + } + else { + $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'" + Write-Output $errorMsg + CSLog -Message $errorMsg -Severity 2 + return + } + } + + # Construct payload for restore + $payload = @{ + name = $TaskName + snapshotEnvironment = $protectionGroup.environment + } + + $payload['oracleParams'] = @{} + $payload['oracleParams']['objects'] = @( + @{ + snapshotId = $SnapshotId + } + ) + $payload['oracleParams']['recoveryAction'] = 'RecoverApps' + $payload['oracleParams']['recoverAppParams'] = @{ + targetEnvironment = 'kOracle'; + oracleTargetParams = @{ + recoverToNewSource = $true; + newSourceConfig = @{ + host = @{ + id = $TargetSourceId + }; + recoveryTarget = 'RecoverDatabase'; + recoverDatabaseParams = @{ + bctFilePath = if ($BCTFilePath) { $BCTFilePath } else { $null }; + databaseName = $NewDatabaseName; + dbFilesDestination = if ($DatabaseFileDestination) { $DatabaseFileDestination } else { $OracleHome } + enableArchiveLogMode = $EnableArchiveLogMode.IsPresent; + nofilenameCheck = $NoFilenameCheck.IsPresent; + numTempfiles = if ($NumTempFiles) { $NumTempFiles } else { $null }; + oracleBaseFolder = $OracleBase; + oracleHomeFolder = $OracleHome; + redoLogConfig = @{ + groupMembers = @($RedoLogMemberPath) + memberPrefix = if ($RedoLogMemberPrefix) { $RedoLogMemberPrefix } else { $null }; + numGroups = $NumRedoLogGroup + sizeMBytes = if ($RedoLogSizeInMb) { $RedoLogSizeInMb } else { 20 } + } + } + } + }; + } + + $restoreURL = '/v2/data-protect/recoveries' + $payloadJson = $payload | ConvertTo-Json -Depth 100 + + $resp = Invoke-RestApi -Method 'Post' -Uri $restoreURL -Body $payloadJson + if ($Global:CohesityAPIStatus.StatusCode -eq 201) { + $resp + } + else { + $errorMsg = $Global:CohesityAPIStatus.ErrorMessage + ", File operation : Failed to recover." + Write-Output $errorMsg + CSLog -Message $errorMsg + } + } + End { + } +} \ No newline at end of file