rubrikinc / rubrik-powershell-sdk

The Rubrik Security Cloud SDK
https://www.powershellgallery.com/packages/RubrikSecurityCloud
MIT License
7 stars 8 forks source link

createOnDemandMssqlBackup Wait For Completion #61

Open Bryan-Meier opened 5 months ago

Bryan-Meier commented 5 months ago

Hello,

We have been using the older CDM Powershell module and are looking to move to this one. The equivalent to using the createOnDemandMssqlBackup mutation in the older CDM Powershell SDK allowed us to add a flag to wait for the job to complete. Can this flag be added to this mutation to bring its capabilities in line with the older SDK?

By not including that option it's now on the customer to write their own wait logic which we are struggling to find a cmdlet that will provide us the the status based on the job id let alone iterate on it until it finishes.

guirava commented 4 months ago

Resolution here depends on first resolving https://github.com/rubrikinc/rubrik-powershell-sdk/issues/60 Engineering is still working on it, we will circle back.

SahFari commented 4 months ago

My work around: $Status = Get-RscEventSeries -List | Where-Object {$_.ObjectId -eq $cdmdb.id} | Select-Object LastActivityStatus, ObjectType, ObjectId, ActivitySeriesId, Fid

    do {
        $Status = Get-RscEventSeries -List | Where-Object {$_.ObjectId -eq $cdmdb.id} | Select-Object LastActivityStatus, ObjectType, ObjectId, ActivitySeriesId, Fid
        Write-host "Backup is still running!"

    } while ( $Status.LastActivityStatus -ne 'SUCCESS' )
clumnah commented 4 months ago
Connect-Rsc @ConnectRsc
$RscAccount = Get-RscAccount
$ClusterName = ""
$RscCluster = Get-RscCluster -Name $ClusterName
$HostName = ""
$RscMssqlInstance = Get-RscMssqlInstance -RscCluster $RscCluster -HostName $HostName
$DatabaseName = ""
$RscMssqlDatabase = Get-RscMssqlDatabase -Name $DatabaseName -RscMssqlInstance $RscMssqlInstance

$RecoveryDateTime = Get-RscMssqlDatabaseRecoveryPoint -RscMssqlDatabase $RscMssqlDatabase -Latest
$RscRequest = New-RscMssqlRestore -RscMssqlDatabase $RscMssqlDatabase -RecoveryDateTime $RecoveryDateTime -FinishRecovery
$RscRequest

$query = New-RscQuery -GqlQuery jobInfo
$query.Var.input = New-Object RubrikSecurityCloud.Types.JobInfoRequest
$query.Var.input.accountname = $RscAccount.AccountId
$query.Var.input.requestId = $RscRequest.id
$query.Var.input.clusterUUID = $RscCluster.Id
$query.Var.input.type = "MSSQL_RESTORE"
$query.Var.input.additionalinfo = New-Object RubrikSecurityCloud.Types.JobInfoRequestDetails
$query.Var.input.additionalinfo.mssqlDbInfo = New-Object RubrikSecurityCloud.Types.MssqlDbInfo
$query.Var.input.additionalinfo.mssqlDbInfo.mssqlDbFid = $RscMssqlDatabase.id
# $Result = $query.Invoke()

do {
    $Result = $query.Invoke()
    $Result.Status
    Start-Sleep -Seconds 1
} until ($Result.Status -eq "SUCCESS" -or $Result.Status -eq "FAILURE")

$Result.Status

Change the values for $ClusterName, $HostName, and $DatabaseName to values for your environment.

Then in the code, change the line $query.Var.input.type = "MSSQL_RESTORE" to appropriate to your operation. The proper values are

SahFari commented 4 months ago

Tnx Chris.

JVGH commented 3 months ago

@clumnah, I want to periodically check the status of a snapshot export. There is no "cluster" setup. I have the source AG/instance/host/db names. How do I query that? The above sample code doesn't work since I do not have a cluster (nor is it possible to set it up by me, we mainly use it take snapshots periodically). Also, the service account doesn't have admin rights for security reasons.

After queuing up an export the response is something like this.. { "EndTime": null, "Id": "RESTORE_MSSQL_DB_1231dec8-85ca-4618-8c41-3ca61e371294_7abc9ac3-c1a3-4d77-ab11-4cca51bav8e4:::0", "NodeId": null, "Progress": null, "StartTime": null, "Status": "QUEUED", "Error": null, "Links": null }

clumnah commented 3 months ago

I do not follow your question. If you are using Rubrik to backup a MSSQL Database, then you have to have a cluster to write the backups to. Can you clarify what you mean?

JVGH commented 3 months ago

@clumnah,

(from the above code sample)

$ClusterName = ""
$RscCluster = Get-RscCluster -Name $ClusterName

On the Rubrik's website, under Inventory > SQL Server Databases, I see a list of hosts/instances. They all have a Cluster (as shown in one of the columns on that list). When I put in that name, the GET-RscCluster doesn't return anything. So I assumed it required some other "cluster" info (e.g. on the Rubrik's UI/dashboard > Clusters tab, this shows "0 total clusters").

How do I get the data in that case? Also, the following query seems to require admin rights for the SA (believe this is the query being called for $RscAccount = Get-RscAccount). Giving that SA admin rights might not be possible at the workplace.

query QueryAccountId {
accountId
}

I'm trying to fetch status of an export I queued up at an interval. When I queue up an export, below is the response. How do I query the status for this id until it succeeds or fails? Your sample code seems to be the answer but I haven't had a success with it for aforementioned reasons.

{
"EndTime": null,
"Id": "RESTORE_MSSQL_DB_1231dec8-85ca-4618-8c41-3ca61e371294_7abc9ac3-c1a3-4d77-ab11-4cca51bav8e4:::0",
"NodeId": null,
"Progress": null,
"StartTime": null,
"Status": "QUEUED",
"Error": null,
"Links": null
}
clumnah commented 3 months ago

I think this will be best served via a Support Ticket. This is is no longer about the SDK and about the RBAC permissions you need to get the cluster info and account name.

You can shortcut the account name by looking at your RSC URL and take the part before the my.rubrik.com. However not having cluster info will be a bigger issue that you still need to solve. While you may not be using replication now, if you do, you wont be able to do actions without the cluster object.

I can help the support tech once the ticket is in if they need it.

JVGH commented 3 months ago

@clumnah : There's is already an open support ticket. If you are ok, may I shoot you an email (at the email specified in your profile) with the ticket number (unsure if DM's work on github)?

ChrisM-Dev commented 3 months ago

The graphql response to this says "only user with Admin or Owner role allowed to access the field".

clumnah commented 3 months ago

@clumnah : There's is already an open support ticket. If you are ok, may I shoot you an email (at the email specified in your profile) with the ticket number (unsure if DM's work on github)?

Yes, that is fine.

SahFari commented 1 month ago

-WaitForCompletion works after upgrade to Rubrik cmdlet (9.0.1)

$Database_ids | ForEach-Object{

    $backupjob = New-RubrikSnapshot -id $ -SLA $Sla -Confirm:$false

    Get-RubrikRequest -id $backup_job.id -Type mssql -WaitForCompletion #-Verbose

}