Created
July 8, 2021 17:25
-
-
Save mritsurgeon/863db1ac0ae59d2b7ed1e2381896635c to your computer and use it in GitHub Desktop.
Get GFS expiry by day based Retention ( Veeam)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue | |
#Connect-VBRServer -Server localhost | |
#Use backup Older than X Days | |
$olderthandays = 3 | |
#GFS Set Your retention | |
$Monthly = 6 | |
$weekly = 8*7 | |
$daily = 7 | |
$allstoragesM = @() | |
$allstoragesW = @() | |
$allstoragesN = @() | |
$backups = get-vbrbackup | |
$oldestBackupDate = (Get-Date) - (New-TimeSpan -Days $olderthandays) | |
$DateStr = $oldestBackupDate.ToString("MM/dd/yyyy hh:mm:ss tt") | |
foreach ($backup in $backups) { | |
foreach ($storage in $backup.getallstorages() | Where {$_.CreationTime -le $DateStr}| ?{$_.GfsPeriod -match "Monthly"} ) { | |
$allstoragesM += New-Object -TypeName psobject -Property @{ | |
JobName=$backup.Name; | |
Time=$storage.CreationTime.ToString("MM/dd/yyyy"); | |
Path=$storage.Info.FilePath; | |
BackupSizeGB=[math]::round(($storage.Info.Stats.BackupSize/1GB),2); | |
DataSizeGB=[math]::round(($storage.Info.Stats.DataSize/1GB),2); | |
GfsRetention="Monthly"; | |
Expiry=($storage.CreationTime).AddMonths(+$Monthly).ToString('MM-dd-yyyy') | |
} | |
} | |
} | |
foreach ($backup in $backups) { | |
foreach ($storage in $backup.getallstorages() | Where {$_.CreationTime -le $DateStr}| ?{$_.GfsPeriod -CEQ "Weekly"} ) { | |
$allstoragesW += New-Object -TypeName psobject -Property @{ | |
JobName=$backup.Name; | |
Time=$storage.CreationTime.ToString("MM/dd/yyyy"); | |
Path=$storage.Info.FilePath; | |
BackupSizeGB=[math]::round(($storage.Info.Stats.BackupSize/1GB),2); | |
DataSizeGB=[math]::round(($storage.Info.Stats.DataSize/1GB),2); | |
GfsRetention="weekly"; | |
Expiry=($storage.CreationTime).Adddays(+$weekly).ToString('MM-dd-yyyy') | |
} | |
} | |
} | |
foreach ($backup in $backups) { | |
foreach ($storage in $backup.getallstorages() | Where {$_.CreationTime -le $DateStr}| ?{$_.GfsPeriod -CEQ "none"} ) { | |
$allstoragesN += New-Object -TypeName psobject -Property @{ | |
JobName=$backup.Name; | |
Time=$storage.CreationTime.ToString("MM/dd/yyyy"); | |
Path=$storage.Info.FilePath; | |
BackupSizeGB=[math]::round(($storage.Info.Stats.BackupSize/1GB),2); | |
DataSizeGB=[math]::round(($storage.Info.Stats.DataSize/1GB),2); | |
GfsRetention="Dailys"; | |
#Expiry=($storage.CreationTime).Adddays(+$daily).ToString('MM-dd-yyyy') | |
} | |
} | |
} | |
$allstoragesM = $allstoragesM | Sort-Object -Property JobName,Time | |
$allstoragesM | select -property Jobname,Time,Path,BackupSizeGB,DataSizeGB,GfsRetention,Expiry | ConvertTo-Csv -Delimiter "," > c:\Monthly.csv | |
$allstoragesW = $allstoragesW | Sort-Object -Property JobName,Time | |
$allstoragesW | select -property Jobname,Time,Path,BackupSizeGB,DataSizeGB,GfsRetention,Expiry | ConvertTo-Csv -Delimiter "," > c:\Weekly.csv | |
#$allstoragesN = $allstoragesN | Sort-Object -Property JobName,Time | |
#$allstoragesN | select -property Jobname,Time,Path,BackupSizeGB,DataSizeGB,GfsRetention,Expiry | ConvertTo-Csv -Delimiter "," > c:\Incriments.other.csv | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment