PowerShell script exchange
Post Reply
jbyoon
Novice
Posts: 6
Liked: never
Joined: Feb 06, 2020 12:07 pm
Full Name: YOON JOO BYOUNG
Contact:

Question - Backup Job check powershell for Last 24 hours

Post by jbyoon »

1. I want to check the status (success/failure) of the backup job executed within 24 hours of the current time with PowerShell.

2. In the case of VMware backup, you could check with the PowerShell below. (Check the backup status for the last 10 days for the VM)

Get-VBRBackupSession | ?{$_.CreationTime -ge (Get-Date).AddDays(-10)} | Select JobName, JobType, CreationTime, Result, @{Name="BackupSize";Expression={$_.BackupStats.BackupSize}} | Sort CreationTime | Format-Table
Image

3. By the way, the backup job of Agent (Windows and Linux) is not output with the above PowerShell. and I would like to display the status of the Agent job as in PowerShell for VMware Backup.

4. How can I check the status (success/failure) of VM and physical machine full backup jobs?

oleg.feoktistov
Veeam Software
Posts: 847
Liked: 300 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Question - Backup Job check powershell for Last 24 hours

Post by oleg.feoktistov »

Hi,

So, let me recap. The main points are two:

1. Get all backup job sessions ran for the last 24 hours. Datetime class has another method for that. Since you already use AddDays(), I guess you can easily figure out how it's called for hours.

2. Get agent backup job sessions. Use Get-VBRComputerBackupJobSessions cmdlet for that.

Thanks,
Oleg

jbyoon
Novice
Posts: 6
Liked: never
Joined: Feb 06, 2020 12:07 pm
Full Name: YOON JOO BYOUNG
Contact:

Re: Question - Backup Job check powershell for Last 24 hours

Post by jbyoon »

Thanks, oleg.feoktistov !!

Thanks to you, I made a PowerShell to check the backup status of the physical server.

Code: Select all

foreach ($PBackup_job in (Get-VBRComputerBackupJob | Select Name)) {
	$PBackup_job_name = $PBackup_job.Name
	Get-VBRComputerBackupJobSession -Name $PBackup_job_name | Where-Object { $_.CreationTime -gt (Get-Date).AddDays(-1)} | Sort CreationTime | Format-Table  
	}
But, in the
$_.CreationTime -gt (Get-Date).AddDays(-1)

part, the result value one day before I want is not displayed, but the contents of the entire date are displayed.


This option works without any problems in below..

Code: Select all

Get-VBRBackupSession | ?{$_.CreationTime -ge (Get-Date).AddDays(-1)} | Select JobName, JobType, CreationTime, endtime, result, state, @{Name="BackupSize";Expression={$_.BackupStats.BackupSize}} | Sort CreationTime | Format-Table


OutPut:
JobName JobType CreationTime         EndTime               Result   State  BackupSize
------- ------- ------------         -------               ------   -----  ----------
VM_Job   Backup 3/21/2021 8:17:49 AM 3/21/2021 8:41:59 AM Warning Stopped 18063425536

Anyone ask help me.

oleg.feoktistov
Veeam Software
Posts: 847
Liked: 300 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Question - Backup Job check powershell for Last 24 hours

Post by oleg.feoktistov »

Hi,
the result value one day before I want is not displayed, but the contents of the entire date are displayed.
Sorry, I'm not sure what you mean by that.

Try using AddHours() method on Get-Date, looks like it fits more in your case.

Thanks,
Oleg

jbyoon
Novice
Posts: 6
Liked: never
Joined: Feb 06, 2020 12:07 pm
Full Name: YOON JOO BYOUNG
Contact:

Re: Question - Backup Job check powershell for Last 24 hours

Post by jbyoon »

thank you for the reply.

I've tried running 2 powershells to check the status of backup jobs that have been running for 24 hours from the current time.

1. Where-Object { $_.CreationTime -ge (Get-Date).AddDays(-1)}
Image

2. Where-Object { $_.CreationTime -ge (Get-Date).AddHours(-1)}
- AddHours(-1) ~ AddHours(-4) = Not OutPut
- AddHours(-5) ~ AddHours(-6) ..... = All DATA OutPut

Image

I only want to outputs a list of backup jobs within 24 hours. By the way, the above PowerShell command outputs a list of backup jobs for all periods.
Which command should I apply to get the result I want?

morciodm
Lurker
Posts: 2
Liked: never
Joined: Sep 04, 2018 3:03 pm
Full Name: debra morcio
Contact:

Re: Question - Backup Job check powershell for Last 24 hours

Post by morciodm »

Are there fields specific to NAS File Share backups? these are not being reflected in my Veeam backup daily report? its only VM's

oleg.feoktistov
Veeam Software
Posts: 847
Liked: 300 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Question - Backup Job check powershell for Last 24 hours

Post by oleg.feoktistov » 1 person likes this post

@jbyoon,

For some reason, the output of Get-VBRComputerBackupJobSession cannot be filtered and sorted directly.
Try the approach below:

Code: Select all

$date = (Get-Date).AddHours(-24)
$sessions = Get-VBRComputerBackupJobSession
$sessions | where {$_.CreationTime -ge $date} | sort CreationTime | Format-Table
Thanks,
Oleg

oleg.feoktistov
Veeam Software
Posts: 847
Liked: 300 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Question - Backup Job check powershell for Last 24 hours

Post by oleg.feoktistov »

@morciod,

Could you, please, describe which specific fields do you mean?

Thanks,
Oleg

jbyoon
Novice
Posts: 6
Liked: never
Joined: Feb 06, 2020 12:07 pm
Full Name: YOON JOO BYOUNG
Contact:

Re: Question - Backup Job check powershell for Last 24 hours

Post by jbyoon »

@oleg.feoktistov
You are really great !!
Thanks for giving me tremendous help.

Thanks to your help, I created the final PowerShell script like the one below.

Code: Select all

$date = (Get-Date).AddHours(-24)
$sessions = Get-VBRComputerBackupJobSession
foreach ($PBackup_job in (Get-VBRComputerBackupJob | Select Name)) {
	$PBackup_job_name = $PBackup_job.Name
	write "------------   Physical Server Backup Job Name : $PBackup_job_name   ------------"
	$sessions | where {$_.CreationTime -ge $date} | sort CreationTime | Select CreationTime, endtime, result, state | Format-Table
	}
Image

jbyoon
Novice
Posts: 6
Liked: never
Joined: Feb 06, 2020 12:07 pm
Full Name: YOON JOO BYOUNG
Contact:

Re: Question - Backup Job check powershell for Last 24 hours

Post by jbyoon »

I created a PowerShell that outputs the status of two types of backup jobs(VM and physical server) within 24 hours.
Thanks to everyone who helped. :)

Code: Select all

Add-PSSnapin Veeampssnapin
$date = (Get-Date).AddHours(-24)
$VMsessions = Get-VBRBackupSession
$VMsessions | where {$_.CreationTime -ge $date} |Select  @{Name="Type";Expression={"VM"}},@{Name="JobName";Expression={$_.JobName}}, CreationTime, endtime, result, state | Sort CreationTime | Format-Table

$PMsessions = Get-VBRComputerBackupJobSession
foreach ($PBackup_job in (Get-VBRComputerBackupJob | Select Name)) {
	$PBackup_job_name = $PBackup_job.Name
	$PMsessions | where {$_.CreationTime -ge $date} | sort CreationTime | Select @{Name="Type";Expression={"PM"}},@{Name="JobName";Expression={$PBackup_job_name}},CreationTime, endtime, result, state | Format-Table
}
Image

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests