PowerShell script exchange
Post Reply
karapoti
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 12, 2018 12:22 am
Full Name: Adrian Robinson
Contact:

report:: VM / backup job / repository / copy job / repository ?

Post by karapoti »

Hi All,

Is there cunning way to use powershell output a list/table of protected VMs which shows:

VMname Backup Job Backup Repository Copy Job Copy Repository

Bonus points for includeing the date of the most recent recovery point in backup and copy :D

I'm able to list VMname and Backup Job, but can't figure out how to extend it...

Code: Select all

$vm_jobs = Get-VBRJob  -WarningAction SilentlyContinue | ?{$_.JobType -eq "Backup"}

$report = foreach ($job in $vm_jobs){

    $job_object = Get-VBRJobObject -Job $job.Name
    
    foreach ($object in $job_object){
    [PSCustomobject]@{
        VMName = $object.Name
        Job    = $job.Name
        }
    }
}
jorgedlcruz
Veeam Software
Posts: 1372
Liked: 619 times
Joined: Jul 17, 2015 6:54 pm
Full Name: Jorge de la Cruz
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by jorgedlcruz »

Hello karapoti,
Quick question related to this. Do you guys have Veeam ONE installed, or even licensed? It should say Availability Suite on the license?
Jorge de la Cruz
Senior Product Manager | Veeam ONE @ Veeam Software

@jorgedlcruz
https://www.jorgedelacruz.es / https://jorgedelacruz.uk
vExpert 2014-2024 / InfluxAce / Grafana Champion
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by david.domask »

@karapoti,

I would advise Veeam One also as it has built-in reports for this.

If you must go the powershell route, I'd actually advise change your approach.

Right now you're checking on Job Objects, which doesn't actually guarantee that the item is backed up, so it's better to check against the backups for each job.

The relationship within the CJob Object properties to track linked jobs is documented here: post444317.html#p444317

So I suppose what you want to do is:

1. Parse all your backup copies and find their linked jobs/repositories
2. Use the JobIDs obtained from the Backup Copies and get the Source Jobs
3. Get-VBRBackup with both
4. Compare the lists and ensure that the machines are tracked in both.
5. You can get the most recent restore points for each machine with Get-VBRRestorePoint

Give it a shot and see what you come up with. It is a bit of legwork here, which is why I recommend Veeam One, but if that's not an option, try to pump something out first and let's see what bumps you hit.
David Domask | Product Management: Principal Analyst
karapoti
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 12, 2018 12:22 am
Full Name: Adrian Robinson
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by karapoti »

Thanks!! I do have Veeam ONE, but prefer a PS1 type report as its tunable to what I need and will help me with the 1300+ client migrations I'm about to embark on with this customer.

I'll make a start and show you what i come up with (bit of a PS1 hack, but find it incredibly useful for all sorts of migrations).
karapoti
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 12, 2018 12:22 am
Full Name: Adrian Robinson
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by karapoti »

So...

I could find LinkedJobs and LinkedJobIds from a copyjob:

Code: Select all

[size=85]$copyjob = get-vbrbackup -name ORB-VMW-1m1m-to-ETT-S02-Rep01

LinkedJobs                   : {1a101fc8-7d82-486c-a6cd-cd0b9fc48930}
LinkedJobIds                 : {a46f31de-1cea-498e-aede-c3ca3a3272ad}[/size]
But can''t find any details using either of those IDs:

Code: Select all

[size=85]PS C:\Users\xx> get-vbrbackup -Id 1a101fc8-7d82-486c-a6cd-cd0b9fc48930

PS C:\Users\xx> get-vbrbackup -id a46f31de-1cea-498e-aede-c3ca3a3272ad

PS C:\Users\xx> [/size]
Using the name of the backupjob I can get an id which yeilds a response:

Code: Select all

[size=85]get-vbrbackup -name ORB-VMW-1m1m-General | Select id, jobid | fl

Id    : 2771346f-6abd-4908-825f-0235bafece9c
JobId : a46f31de-1cea-498e-aede-c3ca3a3272ad

Get-VBRbackup -id 2771346f-6abd-4908-825f-0235bafece9c

Job Name                  Type            Creation Time               VM count
--------                  ----            -------------               --------
ORB-VMW-1m1m-General      VMware Backup   14/10/2022 6:10:2...               1
[/size]
How do I search based on JobID? I think that's my issue ....
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by david.domask » 1 person likes this post

Hi @karapoti

Get-VBRJob | Where-Object {$_.id -eq "the job uuid you found}

Give it a shot :)
David Domask | Product Management: Principal Analyst
karapoti
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 12, 2018 12:22 am
Full Name: Adrian Robinson
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by karapoti »

This is what I've come up with. Ive no doubt it could be more efficient, 'cause I'm just bashing my way through / learning as I go:
Might, for bonus points, add in the recovery points later. But this is what I was trying to acheive.

Thanks for your pointers!

Code: Select all

[size=85]# get vm, windows, and linux agent backups
$backuplist = get-vbrjob | where-object {($_.IsBackup -eq $true) -or ($_.IsEpPolicy -eq $true) }

# get copyjobs
$copyjobs   = Get-VBRjob | where {($_.IsBackupCopy -eq $true)}

# create an array which has BackupJob, its Id, Copyjob the backup job is in, and the copyjob ID.
$backup_copy_lookup = foreach ($copyjob in $copyjobs){
    
    foreach($linkedjobid in $copyjob.linkedjobids){
        
        $BackupJobName = ($backuplist | where-object {$_.Id -eq $linkedjobid}).Name
            
        [PSCustomobject]@{
            Backupjob    = $BackupJobName
            Linkedjobid  = $linkedjobid
            Copyjob      = $copyjob.name
            Copyjobid    = $copyjob.id
            }
    }
}

# get all clients in backup jobs, and cross reference within $backup_copy_lookup
# needs to be done for VM backups and agent backups


## VM filtering
$VMJobList = Get-VBRJob | where {($_.IsBackupCopy -ne $true) -and ($_.IsBackup -eq $true) }

$vm_backup_lookup = foreach($Jobobject in $VMJobList){

    $Objects = $JobObject.GetObjectsInJob()

    foreach($object in $objects){

    [PSCustomobject]@{
        ClientName = $object.Name
        BackupType = $Jobobject.TypeToString
        BackupJob  = $jobobject.Name
        }
    }
}

## agent filtering
$AgentJobList = Get-VBRComputerBackupJob | where-object { $_.ScheduleEnabled -eq $true}

$agent_backup_lookup = foreach ($job in $AgentJobList){
 
     foreach($backupobject in $job.BackupObject){
        
        $PG = Get-VBRProtectionGroup -name $backupobject.Name

        foreach ($object in $PG.container.customcredentials){
        [PSCustomobject]@{
            ClientName  = $object.HostName
            BackupType  = $job.OSPlatform
            BackupJob   = $job.Name
            }
        }
    }
}


## join the two backup lookups together
$combined_backup_lookup = $vm_backup_lookup + $agent_backup_lookup

# go through each client in $combined_backup_lookup and match details in $backup_copy_lookup
$report = foreach($client in $combined_backup_lookup){

$client_copy_job = $backup_copy_lookup | Where-Object {$_.BackupJob -eq $client.backupjob}

    [PSCustomobject]@{
        ClientName = $client.ClientName
        BackupType = $client.BackupType
        BackupJob  = $client.BackupJob
        CopyJob    = $client_copy_job.Copyjob
        }

}

$report | ft -AutoSize[/size]
Filtered output, which lets me see what backup/copyjob a client is in:

Code: Select all

[size=85]
ClientName		BackupType		BackupJob			CopyJob
host1			VMware Backup		ETT-VMW-3m3m-General	ETT-VMW-3m3m-to-ORB-SO2-Rep01
host2			VMware Backup		WLG-VMW-1m1m-General	WLG-VMW-1m1m-to-ETT-S04-Rep01
host3			VMware Backup		ETT-VMW-3m7y-DFS		ETT-VMW-3m7y-to-ORB-SO4-Rep01
host4			VMware Backup		ETT-VMW-1m1m-General	ETT-VMW-1m1m-to-ORB-SO2-Rep01
host5			Windows			ORB-WIN-1m1m-General	ORB-WIN-1m1m-to-ETT-S01-Rep01
host6			Linux			ORB-LIN-3m3m-General	ORB-LIN-3m3m-to-ETT-S03-Rep01
host7			Linux			ETT-LIN-1m1m-General	ETT-LIN-1m1m-to-ORB-SO4-Rep01
host8			Linux			ETT-LIN-3m3m-General	ETT-LIN-3m3m-to-ORB-SO4-Rep01
[/size]
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by david.domask »

Wonderful! It looks really good I'd say :)

When you're ready to tackle the restore points, it should be pretty fast with just Get-VBRRestorepoint; you already have a list of the Job Object names, so you'll just pass the job to Get-VBRBackup, then the CBackup object to Get-VBR Restorepoint, and you can match on the names good enough I think.
David Domask | Product Management: Principal Analyst
karapoti
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 12, 2018 12:22 am
Full Name: Adrian Robinson
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by karapoti »

I've worked in the number of restorepoints, now trying to figure out how to differentiate between a local one and a remote one
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by oleg.feoktistov »

Hi Adrian,

What do you mean by remote restore points? Those residing on capacity or archive tier of a scale-out repository?
If that's the case, check this thread.

Best regards,
Oleg
karapoti
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 12, 2018 12:22 am
Full Name: Adrian Robinson
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by karapoti »

I have local on SOBR (with linux backed repo), and remote on StoreOnce.
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by david.domask »

Well, to be honest the question is a bit surprising for me :)

Get-VBRRestorePoint and Get-VBRBackup will return unique objects for the Primary Backup and the Backup Copy, so it's just a matter of using the properties to suss-out the repository it's on or the job.

What I mean for example is that CBackup Objects have a property JobName which you can use to identify the source job and an unsupported but stable method GetRepositoryName() to print the repository name.

COib objects are a bit trickier as they don't have a direct link to the job information, but I'm assuming you're probably getting the Restore Points with Get-VBRRestorePoint -Backup $backup, so you can just write a function that pulls the relevant repository information from the CBackup Object, then goes on to parse the RestorePoint information and print both side by side.
David Domask | Product Management: Principal Analyst
karapoti
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 12, 2018 12:22 am
Full Name: Adrian Robinson
Contact:

Re: report:: VM / backup job / repository / copy job / repository ?

Post by karapoti »

Yeah, i've been blindly trying to match UUIDs between things and going a bit cross eyed.

Will chase down the GetRepositoryName() path today.
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests