PowerShell script exchange
Post Reply
dmeddock@techgen.com
Novice
Posts: 3
Liked: never
Joined: Oct 07, 2019 9:22 pm
Full Name: Dan Meddock
Contact:

File Level Restore Script - Exclude System Reserved Volume

Post by dmeddock@techgen.com » Oct 07, 2019 9:33 pm

I have a script I created to run through all jobs and restore a specified file to test the backups of every VM in every job for every volume.
I'm trying to find a way to exclude the system reserve volume, but so far the best thing I could think of was to exclude Volume0 which is usually the system reserve volume. This works but I'm worried about servers that might not have that the system reserve volume. I'd rather have this setup to exclude volumes that are like 20GB or less, so it will skip the system reserve volume and any USB volumes. Maybe skipping Volume0 is the way to go in this scenario, idk. Any help would be greatly appreciated!

HannesK
Veeam Software
Posts: 4044
Liked: 497 times
Joined: Sep 01, 2014 11:46 am
Location: Austria
Contact:

Re: File Level Restore Script - Exclude System Reserved Volume

Post by HannesK » Oct 08, 2019 7:08 am

Hello,
and welcome to the forums.

If you have your testfile always in the same path, then I would just scan all volumes and throw an error if nothing was found for a machine. As everything is mounted to c:\veeamflr, it does not take any time to check all volumes.

Best regards,
Hannes

dmeddock@techgen.com
Novice
Posts: 3
Liked: never
Joined: Oct 07, 2019 9:22 pm
Full Name: Dan Meddock
Contact:

Re: File Level Restore Script - Exclude System Reserved Volume

Post by dmeddock@techgen.com » Oct 09, 2019 9:09 pm

But is there a way for me to check the volumes or check the volume space or some way to exclude the system reserve volume? Currently I have it skipping Volume0 to accomplish this. But once I have to scale the script that might become and issue. So I want to find a way to check each volume. The testfile part is working just fine. I just want the script to recognize the system reserve volume and skip trying to do a FLR. So my script works fine currently just trying to future proof it a bit.

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

Re: File Level Restore Script - Exclude System Reserved Volume

Post by oleg.feoktistov » Oct 14, 2019 10:28 am

Hi Dan,

Can you, please, share the script part where it runs for the jobs and excludes Volume0?

Thanks,

dmeddock@techgen.com
Novice
Posts: 3
Liked: never
Joined: Oct 07, 2019 9:22 pm
Full Name: Dan Meddock
Contact:

Re: File Level Restore Script - Exclude System Reserved Volume

Post by dmeddock@techgen.com » Oct 22, 2019 9:31 pm

Code: Select all

# Script to do File Level Restore Testing for Veeam Backup jobs.
Add-PSSnapin VeeamPSSnapin
New-Eventlog -LogName Application -Source "File Restore Testing"

# Get a list of all jobs in Veeam
foreach ($job in Get-VBRJob)
{
		
	$vms = Get-VBRJobObject -job $job.name
	foreach ($vm in $vms)
	{
		$WFLR = Get-VBRRestorePoint -Name $vm.name | Sort CreationTime -Descending | Select -First 1 | Start-VBRWindowsFileRestore
		#Split string into an array of drives 
		$driveArrays = $WFLR.drives -split ', '
		# FLR testing report directory
		$restoreDir = "C:\Special Restores\report.txt"
		# Get today's date
		$todaysDate = (get-date).ToString("yyyyMMdd")		
		
		#Iterate through all drives, one at a time     
		Foreach ($drive in $driveArrays) 
		{     
			# Splits drives string up into an array to extract Volume name and VM name
			$volumeArray = $drive -split '\\' 	
			# Get volume name
			$volume = $volumeArray[3]	
			# Clean up VM name
			$vmArray = $volumeArray[2] -split '_'	
			# Get VM name
			$virtualMachine = $vmArray[0]	
			# Set file path to variable
			$restoreFile = "$drive\restoretesting.txt"	
			# Check if file exists
			$FileExists = Test-Path -LiteralPath $restoreFile
			# Get date from one week ago
			$lastWeek = (get-date).AddDays(-7).ToString("yyyyMMdd")
			
			# Skips checking Volume0 since that is usually the System Reserve Partition
			If($volume -notmatch 'Volume0')
			{			
				#If it exists then restore file and log results into log file
				If($FileExists -eq $True) 
				{
					# Pull the date from the first line of the restore file
					$rstFileDate = Get-Content -Path $restoreFile -TotalCount 1
					# Verify the restore file date and ensure its within the past week
					If($rstFileDate -gt $lastWeek)
					{				
						$eventType = "Information"
						copy-item -path $restoreFile -destination "C:\Special Restores\restoreFile-$virtualMachine-$todaysDate.txt"
						$testLog = "[$(Get-Date -format 'u')] [SUCCESS] [$virtualMachine] $volume - Restore file is current and testing completed successfully"
					}
					# If the file exists but the first line containing the date is older than a week; throw warning
					Else 
					{
						$eventType = "Warning"
						copy-item -path $restoreFile -destination "C:\Special Restores\restoreFile-$virtualMachine-OUTofDATE.txt"
						$testLog = "[$(Get-Date -format 'u')] [WARNING] [$virtualMachine] $volume - Restore file is out of date - ($rstFileDate)"
					}	
				}
				# File doesn't Exist in specified directory
				Else 
				{
					$eventType = "Error"
					$testLog = "[$(Get-Date -format 'u')] [FAILED] [$virtualMachine] $volume is missing $restoreFile"
				}
			# Write results to log file and append post results
			Add-Content -Path $restoreDir -Value $testLog
			# Write results to event log
			Write-EventLog -LogName Application -Source "File Restore Testing" -EntryType $eventType -EventId 6969 -Message $testLog
			}
						
		} 
		#End the file level restore
		Stop-VBRWindowsFileRestore $WFLR
	}	
}
Here is a basic version of my script. I want to be able to exclude system reserve volumes. Since the FLR in the Veeam GUI doesnt show the system reserve partition so I figure we should be able to exclude it a better way. Or if we could only run it against partitions with a drive letter. Ive been searching for a solution but unable to find anything useful. Any help would be greatly appreciated.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests