bseltz-cohesity / scripts

Cohesity REST API examples in PowerShell and Python
Apache License 2.0
102 stars 40 forks source link

Convert 365 autoprotect to static job #156

Closed antoineboulent closed 3 months ago

antoineboulent commented 4 months ago

Hi,

I need to convert 365 autoprotect job to an static job but I won't to move object to an new job because the first run will be an full backup and take too time. have you an idea ?

Regards Antoine

bseltz-cohesity commented 4 months ago

Assuming the protection group has run successfully in the past, you could do this:

. .\cohesity-api.ps1
apiauth  -vip mycluster -username admin
$jobs = api get -v2 data-protect/protection-groups?names="my mailbox backup"
$search = api get /searchvms?vmName="my mailbox backup"
$objects = @()
$search.vms | ForEach-Object {$objects = @($objects + @{"id" = $_.vmDocument.objectId.entity.id; "name" = $_.vmDocument.objectId.entity.o365Entity.name})}
$jobs.protectionGroups[0].office365Params.objects = $objects
api put -v2 data-protect/protection-groups/$($jobs.protectionGroups[0].id) $jobs.protectionGroups[0]
antoineboulent commented 4 months ago

Hi,

I try bu have an issue, when à run $search = api get /searchvms?vmName="TEST_AUTOPROTECT", $search is empty

bseltz-cohesity commented 4 months ago

It's a requirement that the protection group must have run before. You can not run it on a new test group that has never ben run.

antoineboulent commented 4 months ago

OK I anderstand.

I run the script on the good policy but à have an other issue : "Connected! validation failure list: validation failure list: validation failure list: objects in body shouldn't contain duplicates"

in this autoprotect job, there is ~16 000 mailbox but ~14 500 excluded because there are in static mailbox backup jobs.

bseltz-cohesity commented 4 months ago

try this:

. .\cohesity-api.ps1
apiauth  -vip mycluster -username admin
$jobs = api get -v2 data-protect/protection-groups?names="my mailbox backup"
$search = api get /searchvms?vmName="my mailbox backup"
$objects = @()
$objectIds = @($search.vms.vmDocument.objectId.entity.id | Sort-Object -Unique) 
$objectIds | ForEach-Object {$objects = @($objects + @{"id" = $_})}
$jobs.protectionGroups[0].office365Params.objects = $objects
api put -v2 data-protect/protection-groups/$($jobs.protectionGroups[0].id) $jobs.protectionGroups[0]