PowerShell script exchange
tri_94
Novice
Posts: 8 Liked: 3 times
Joined: Jan 17, 2020 10:22 am
Full Name: Nick
Contact:
Post
by tri_94 » Jan 17, 2020 10:41 am
1 person likes this post
Can anyone please help me create a powershell export to display the following information.
Job Name
Description
Amount of VM's
Job Size
VM's in Job
Scheduled
Restore Points to Keep
GFS Monthly Backups
GFS Yearly Backups
Retention Policy Type
Job Type
Target
Schedule Options
I was trying to work with this code which most of it has came from this forum already. (credit to Egor Yakovlev,
powershell-f26/get-backup-job-s-target- ... 64121.html ) & Other parts I believe are from Martijn Smit
Its not put together in the best way I'm sure. I just cant see to get it to do what i need.
Can anyone please help
Many Thanks
Nick
Code: Select all
$data = ForEach($BackupCopyJob in (Get-VBRJob | Sort-Object Name)){
$Session = $BackupCopyJob.FindLastSession()
$BackupTotalSize = [math]::round($Session.Info.Progress.TotalUsedSize/1Gb,2)
$backupJobs = Get-VBRBackup -Name $BackupCopyJob.Name
foreach ($job in $backupJobs)
{
$restorePoints = $job.GetAllStorages() | sort CreationTime -descending
$jobBackupSize = 0;
$jobDataSize = 0;
#$jobName = ($job | Select -ExpandProperty JobName);
#Write-Host "Processing backup job: $jobName"
# get list of VMs associated with this backup job
$vmList = ($job | Select @{n="vm";e={$_.GetObjectOibsAll() | %{@($_.name,"")}}} | Select -ExpandProperty vm);
$amountVMs = 0;
$vms = ""
foreach($vmName in $vmList)
{
if([string]::IsNullOrEmpty($vmName)) {
continue
}
$vms += "$vmName,"
$amountVMs = $amountVMs + 1
}
# cut last ,
if(![string]::IsNullOrEmpty($vmName)) {
$vms = $vms.Substring(0, $vms.Length - 1);
}
# go through restore points and add up the backup and data sizes
foreach ($point in $restorePoints)
{
$jobBackupSize += [long]($point | Select-Object -ExpandProperty stats | Select -ExpandProperty BackupSize);
$jobDataSize += [long]($point | Select-Object -ExpandProperty stats | Select -ExpandProperty DataSize);
}
# convert to GB
$jobBackupSize = [math]::Round(($jobBackupSize / 1024 / 1024 / 1024), 2);
$jobDataSize = [math]::Round(($jobDataSize / 1024 / 1024 / 1024), 2);
# format record into an array and save it into the global data array
$newEntry = @{Job=$jobName; VMs=$vms; AmountVMs=$amountVMs; jobBackupSize=$jobBackupSize; jobDataSize=$jobDataSize}
#$global:newBackupData += $newEntry;
# # now do something with these stats! :-)
# Write-Host "Total VMs: " $amountVMs;
# Write-Host "Total Backup Size: " $jobBackupSize;
# Write-Host "Total Data Size: " $jobDataSize;
# Write-Host "List of VMs: " $vms;
# Write-Host "------------";
}
$Options = $BackupCopyJob.GetOptions()
$Properties = New-Object Psobject
$Properties | Add-Member -type Noteproperty -name JobName -value $jobName #$BackupCopyJob.Name
$Properties | Add-Member -type Noteproperty -name Description -value $BackupCopyJob.NameWithDescription
$Properties | Add-Member -type Noteproperty -name "Size in MB" -value $BackupTotalSize
$Properties | Add-Member -type Noteproperty -name "Amount of VMs" -value $amountVMs
$Properties | Add-Member -type Noteproperty -name "Job Size" -value $jobDataSize
$Properties | Add-Member -type Noteproperty -name "VMs in Job" -value $vms
$Properties | Add-Member -type Noteproperty -name IsScheduledEnabled -value $BackupCopyJob.IsScheduleEnabled
$Properties | Add-Member -type Noteproperty -name RestorePointsToKeep -value $Options.generationpolicy.SimpleRetentionRestorePoints
$Properties | Add-Member -type Noteproperty -name GFSMonthlyBackups -value $Options.generationpolicy.GFSMonthlyBackups
$Properties | Add-Member -type Noteproperty -name GFSYearlyBackups -value $Options.generationpolicy.GFSYearlyBackups
$Properties | Add-Member -type Noteproperty -name RetentionPolicyType -value $Options.generationpolicy.RetentionPolicyType
# $Properties | Add-Member -type Noteproperty -name Path -value $BackupCopyJob.TargetDir
$Properties | Add-Member -type Noteproperty -name JobType -value $BackupCopyJob.JobType
$Properties | Add-Member -type Noteproperty -name Target -value $BackupCopyJob.GetTargetRepository().Name
$Properties | Add-Member -type NoteProperty -Name ScheduleOptions -Value $BackupCopyJob.ScheduleOptions.StartDateTimeLocal
#$Properties | Add-Member -type NoteProperty -Name "Schedule Day" -Value $BackupCopyJob.ScheduleOptions.OptionsDaily
#$Properties | Add-Member -type Noteproperty -name "Amount of VMs" -value $amountVMs
Write-Output $Properties
}
#$Data | Export-Csv "d:\test\export1.csv" -NoTypeInformation
$Data
tri_94
Novice
Posts: 8 Liked: 3 times
Joined: Jan 17, 2020 10:22 am
Full Name: Nick
Contact:
Post
by tri_94 » Jan 20, 2020 12:13 pm
1 person likes this post
Using code i've found i've managed to add most of the parts i require using the following code see below.
Only thing i've found is the Replica restore points are not showing correctly. For me it shows 7 but we only have it set to 1.
Thanks
Nick
Code: Select all
$Type = "Backup"
#$Type = "Replica"
#$Type = "BackupSync"
asnp VeeamPSSnapin
Get-VBRJob | ?{$_.JobType -eq "$Type"} | %{
$job = $_
$JobName = $_.Name
$Backup = Get-VBRBackup -Name $JobName
$lastsession = $job.FindLastSession()
$Session = $job.FindLastSession()
foreach($tasksession in $lastsession.GetTaskSessions()) {
$PointsOnDisk = (get-vbrbackup -Name $job.Name | Get-VBRRestorePoint -Name $tasksession.Name | Measure-Object).Count
$BackupTotalSize = [math]::round($Session.Info.Progress.TotalUsedSize/1Gb,2)
$BackupSize = [math]::round($Session.Info.BackedUpSize/1Gb,2)
$RepositoryPath = $Backup.Info.DirPath.ToString()
$LastBackupStart = $Session.CreationTime
$LastResult = $job.GetLastResult()
$Target = $job.GetTargetRepository().Name
$info = $job.GetOptions()
$pointtokeep = $job.Options.GenerationPolicy.SimpleRetentionRestorePoints
$GFSmonthly= $job.Options.generationpolicy.GFSMonthlyBackups
$GFSYearlyBackups = $job.Options.generationpolicy.GFSYearlyBackups
$RetentionPolicyType = $job.Options.generationpolicy.RetentionPolicyType
}
$_ | Get-VBRJobObject | ?{$_.Object.Type -eq "VM"} | Select @{ L="Job"; E={$JobName}}, Name, @{ L="Size"; E={$_.ApproxSizeString}}, @{ L="PointsOnDisk"; E={$PointsOnDisk}}, @{ L="LastResult"; E={$LastResult}}, @{ L="LastBackupStart"; E={$LastBackupStart}}, @{ L="LastBackupTotalSize"; E={$BackupTotalSize}}, @{ L="LastBackupSize"; E={$BackupSize}}, @{ L="RepositoryPath"; E={$RepositoryPath}}, @{ L="Repository"; E={$Target}}, @{ L="Point To Keep"; E={$pointtokeep}}, @{ L="GFS Monthly"; E={$GFSmonthly}}, @{ L="GFS Yearly"; E={$GFSYearlyBackups}}, @{ L="Retention Policy"; E={$RetentionPolicyType}} | Sort -Property Job, Name
} | Export-csv "d:\test\Veeam+$Type.csv" -NoTypeInformation
veremin
Product Manager
Posts: 20397 Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:
Post
by veremin » Jan 20, 2020 2:17 pm
this post
This is how you can get retention policy specified for replication job:
Code: Select all
asnp VeeamPSSnapin
$Job = Get-VBRJob -name "Name of your replication job"
$Options = $Job.getoptions()
$Options.options.rootnode.retaincycles
Should be fairly easy to incorporate this code to the provided script. Let me know, if you need any assistance with that.
Thanks!
tri_94
Novice
Posts: 8 Liked: 3 times
Joined: Jan 17, 2020 10:22 am
Full Name: Nick
Contact:
Post
by tri_94 » Jan 20, 2020 3:53 pm
this post
Thanks for your repy.
I've tried adding it using $Retention = $job.options.rootnode.retaincycles
which i though should of worked.
So i tried this way with
$options = $job.GetOptions()
$Options.options.rootnode.retaincycles
However the output i get is just "Veeam.Backup.Model.CJobOptions"
Code: Select all
$Type = "Backup"
#$Type = "Replica"
#$Type = "BackupSync"
asnp VeeamPSSnapin
Get-VBRJob | ?{$_.JobType -eq "$Type"} | %{
$job = $_
$JobName = $_.Name
$Backup = Get-VBRBackup -Name $JobName
$lastsession = $job.FindLastSession()
$Session = $job.FindLastSession()
foreach($tasksession in $lastsession.GetTaskSessions()) {
$PointsOnDisk = (get-vbrbackup -Name $job.Name | Get-VBRRestorePoint -Name $tasksession.Name | Measure-Object).Count
$BackupTotalSize = [math]::round($Session.Info.Progress.TotalUsedSize/1Gb,2)
$BackupSize = [math]::round($Session.Info.BackedUpSize/1Gb,2)
$RepositoryPath = $Backup.Info.DirPath.ToString()
$LastBackupStart = $Session.CreationTime
$LastResult = $job.GetLastResult()
$Target = $job.GetTargetRepository().Name
$info = $job.GetOptions()
$pointtokeep = $job.Options.GenerationPolicy.SimpleRetentionRestorePoints
$GFSmonthly= $job.Options.generationpolicy.GFSMonthlyBackups
$GFSYearlyBackups = $job.Options.generationpolicy.GFSYearlyBackups
$RetentionPolicyType = $job.Options.generationpolicy.RetentionPolicyType
$Retention = $job.options.rootnode.retaincycles
$options = $job.GetOptions()
$Options.options.rootnode.retaincycles
}
$_ | Get-VBRJobObject | ?{$_.Object.Type -eq "VM"} | Select @{ L="Job"; E={$JobName}}, Name, @{ L="Size"; E={$_.ApproxSizeString}}, @{ L="PointsOnDisk"; E={$PointsOnDisk}}, @{ L="LastResult"; E={$LastResult}}, @{ L="LastBackupStart"; E={$LastBackupStart}}, @{ L="LastBackupTotalSize"; E={$BackupTotalSize}}, @{ L="LastBackupSize"; E={$BackupSize}}, @{ L="RepositoryPath"; E={$RepositoryPath}}, @{ L="Repository"; E={$Target}}, @{ L="Point To Keep"; E={$pointtokeep}}, @{ L="GFS Monthly"; E={$GFSmonthly}}, @{ L="GFS Yearly"; E={$GFSYearlyBackups}}, @{ L="Retention Policy"; E={$RetentionPolicyType}}, @{ L="Retention"; E={$Options}} | Sort -Property Job, Name
}# | Export-csv "d:\test\Veeam+$Type.csv" -NoTypeInformation
veremin
Product Manager
Posts: 20397 Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:
Post
by veremin » Jan 20, 2020 5:12 pm
this post
Something like this should work for replication jobs:
Code: Select all
asnp VeeamPSSnapin
Get-VBRJob | ?{$_.JobType -eq "Replica"} | %{
$job = $_
$JobName = $_.Name
$Backup = Get-VBRBackup -Name $JobName
$lastsession = $job.FindLastSession()
$Session = $job.FindLastSession()
foreach($tasksession in $lastsession.GetTaskSessions()) {
$PointsOnDisk = (get-vbrbackup -Name $job.Name | Get-VBRRestorePoint -Name $tasksession.Name | Measure-Object).Count
$BackupTotalSize = [math]::round($Session.Info.Progress.TotalUsedSize/1Gb,2)
$BackupSize = [math]::round($Session.Info.BackedUpSize/1Gb,2)
$RepositoryPath = $Backup.Info.DirPath.ToString()
$LastBackupStart = $Session.CreationTime
$LastResult = $job.GetLastResult()
$Target = $job.GetTargetRepository().Name
$info = $job.GetOptions()
$pointtokeep = $job.Options.GenerationPolicy.SimpleRetentionRestorePoints
$GFSmonthly= $job.Options.generationpolicy.GFSMonthlyBackups
$GFSYearlyBackups = $job.Options.generationpolicy.GFSYearlyBackups
$RetentionPolicyType = $job.Options.generationpolicy.RetentionPolicyType
$Retention = $info.options.rootnode.retaincycles
}
$_ | Get-VBRJobObject | ?{$_.Object.Type -eq "VM"} | Select @{ L="Job"; E={$JobName}}, Name, @{ L="Size"; E={$_.ApproxSizeString}}, @{ L="PointsOnDisk"; E={$PointsOnDisk}}, @{ L="LastResult"; E={$LastResult}}, @{ L="LastBackupStart"; E={$LastBackupStart}}, @{ L="LastBackupTotalSize"; E={$BackupTotalSize}}, @{ L="LastBackupSize"; E={$BackupSize}}, @{ L="RepositoryPath"; E={$RepositoryPath}}, @{ L="Repository"; E={$Target}}, @{ L="Point To Keep"; E={$pointtokeep}}, @{ L="GFS Monthly"; E={$GFSmonthly}}, @{ L="GFS Yearly"; E={$GFSYearlyBackups}}, @{ L="Retention Policy"; E={$RetentionPolicyType}}, @{ L="Retention"; E={$Retention}} | Sort -Property Job, Name
}# | Export-csv "d:\test\Veeam+$Type.csv" -NoTypeInformation
Thanks!
tri_94
Novice
Posts: 8 Liked: 3 times
Joined: Jan 17, 2020 10:22 am
Full Name: Nick
Contact:
Post
by tri_94 » Jan 21, 2020 11:09 am
1 person likes this post
Thank you again. For some reason it seemed to break the $RepositoryPath when i copied the code from your post above. I used my code from above and added your last lines and it works.
What im not quiet sure on what is the difference between points to keep and retention ?
Thanks
Nick
Working code below
-
Code: Select all
$Type = "Backup"
#$Type = "Replica"
#$Type = "BackupSync"
asnp VeeamPSSnapin
Get-VBRJob | ?{$_.JobType -eq "$Type"} | %{
$job = $_
$JobName = $_.Name
$Backup = Get-VBRBackup -Name $JobName
$lastsession = $job.FindLastSession()
$Session = $job.FindLastSession()
foreach($tasksession in $lastsession.GetTaskSessions()) {
$PointsOnDisk = (get-vbrbackup -Name $job.Name | Get-VBRRestorePoint -Name $tasksession.Name | Measure-Object).Count
$BackupTotalSize = [math]::round($Session.Info.Progress.TotalUsedSize/1Gb,2)
$BackupSize = [math]::round($Session.Info.BackedUpSize/1Gb,2)
$RepositoryPath = $Backup.Info.DirPath.ToString()
$LastBackupStart = $Session.CreationTime
$LastResult = $job.GetLastResult()
$Target = $job.GetTargetRepository().Name
$info = $job.GetOptions()
$pointtokeep = $job.Options.GenerationPolicy.SimpleRetentionRestorePoints
$GFSmonthly= $job.Options.generationpolicy.GFSMonthlyBackups
$GFSYearlyBackups = $job.Options.generationpolicy.GFSYearlyBackups
$RetentionPolicyType = $job.Options.generationpolicy.RetentionPolicyType
$Retention = $info.options.rootnode.retaincycles
}
$_ | Get-VBRJobObject | ?{$_.Object.Type -eq "VM"} | Select @{ L="Job"; E={$JobName}}, Name, @{ L="Size"; E={$_.ApproxSizeString}}, @{ L="PointsOnDisk"; E={$PointsOnDisk}}, @{ L="LastResult"; E={$LastResult}}, @{ L="LastBackupStart"; E={$LastBackupStart}}, @{ L="LastBackupTotalSize"; E={$BackupTotalSize}}, @{ L="LastBackupSize"; E={$BackupSize}}, @{ L="RepositoryPath"; E={$RepositoryPath}}, @{ L="Repository"; E={$Target}}, @{ L="Point To Keep"; E={$pointtokeep}}, @{ L="GFS Monthly"; E={$GFSmonthly}}, @{ L="GFS Yearly"; E={$GFSYearlyBackups}}, @{ L="Retention Policy"; E={$RetentionPolicyType}}, @{ L="Retention"; E={$Retention}} | Sort -Property Job, Name
} | Export-csv "d:\test\Veeam+$Type.csv" -NoTypeInformation
oleg.feoktistov
Veeam Software
Posts: 2010 Liked: 669 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:
Post
by oleg.feoktistov » Jan 21, 2020 4:01 pm
this post
Hi Nick,
In the script $pointtokeep variable represents restore points to keep configured in case
Simple Retention Policy scheme is in place.
And since this policy is applicable only for Backup Copy Jobs, there is no point to appeal to SimpleRetentionRestorePoints property when info is fetched for replication jobs - $Retention variable represents the value you need.
For all other than Backup Copy Job types SimpleRetentionRestorePoints property holds the default value of 7.
Thanks,
Oleg
tri_94
Novice
Posts: 8 Liked: 3 times
Joined: Jan 17, 2020 10:22 am
Full Name: Nick
Contact:
Post
by tri_94 » Jan 22, 2020 10:34 am
this post
Thank you for explaining that.
It now makes some sense.
cptkommin
Novice
Posts: 9 Liked: 3 times
Joined: Apr 17, 2023 6:25 am
Full Name: Fred Lessing
Contact:
Post
by cptkommin » Dec 22, 2023 7:37 am
this post
Hi
I know it's been a while since somebody posted here, but hopefully, I can revive this a bit.
I am using only the below code:
Code: Select all
$Type = "Backup"
#$Type = "Replica"
$Type = "BackupSync"
Get-VBRJob | ?{$_.JobType -eq "$Type"} | %{
$job = $_
$JobName = $_.Name
$Backup = Get-VBRBackup -Name $JobName
$lastsession = $job.FindLastSession()
$Session = $job.FindLastSession()
foreach($tasksession in $lastsession.GetTaskSessions()) {
$BackupTotalSize = [math]::round($Session.Info.Progress.TotalUsedSize/1Gb,2)
$BackupSize = [math]::round($Session.Info.BackedUpSize/1Gb,2)
$LastBackupStart = $Session.CreationTime
$LastResult = $job.GetLastResult()
$info = $job.GetOptions()
}
$_ | Get-VBRJobObject | ?{$_.Object.Type -eq "VM"} | Select @{ L="Job"; E={$JobName}}, Name, @{ L="Size"; E={$_.ApproxSizeString}}, @{ L="LastResult"; E={$LastResult}}, @{ L="LastBackupStart"; E={$LastBackupStart}}, @{ L="LastBackupTotalSize"; E={$BackupTotalSize}}, @{ L="LastBackupSize"; E={$BackupSize}} | Sort -Property Job, Name
}
Issues that I have, that I can't seem to figure out why or what happens is with BackupSync Jobs, it doesn't quite give me the sizes:
Code: Select all
Job : BC - Test - Test-DB01
Name : Test - Test-DB01
Size : 0 B
LastResult : None
LastBackupStart : 2023/12/22 00:00:17
LastBackupTotalSize : 3,32
LastBackupSize : 0
Anyone with an idea as to why this is?
Much appreciated.
#Edited by Mod: Code in code tags
Users browsing this forum: No registered users and 18 guests