Skip to main content

Get Daily backup size for previous 2 weeks.


Scott
Forum|alt.badge.img+9
  • Veeam Legend
  • 1110 comments

This works great for me using forever forward incremental jobs. If you are using synthetic fulls, or reverse you may get unexpected results as your latest job will show as the full size. 


I took my previous script and modified it so I can look at the previous 2 weeks, and see the size of the backup for each day.  If you change the (-14) you can make this weekly, monthly, daily with ease.

 

1# Location of the Veeam backup folder
2$BackupFolderPath = "f:\Backups"
3
4# Start and end dates
5$EndDate = Get-Date
6$StartDate = $EndDate.AddDays(-14)
7
8# Function to convert bytes to GB
9function ConvertTo-GB {
10 param (
11 [Parameter(Mandatory=$true)]
12 [int64]
13 $bytes
14 )
15 return "{0:N2}" -f ($bytes / 1GB) + " GB"
16}
17
18# Go through each day from the start date to the end date
19for ($Date = $StartDate; $Date -le $EndDate; $Date = $Date.AddDays(1)) {
20 # Date in the format 'yyyy-MM-dd'
21 $DateString = $Date.ToString('yyyy-MM-dd')
22
23 # Get all backup files for this date
24 $BackupFiles = Get-ChildItem -Path $BackupFolderPath -Recurse -Filter "*$DateString*"
25
26 # If there's no backup file for this date, continue to the next date
27 if ($BackupFiles -eq $null) {
28 Write-Output "No backup files for the date $DateString were found."
29 continue
30 }
31
32 # Sum up the sizes of all backup files for this date
33 $TotalBackupSizeBytes = 0
34 foreach ($BackupFile in $BackupFiles) {
35 $TotalBackupSizeBytes += (Get-Item $BackupFile.FullName).Length
36 }
37
38 # Convert bytes to GB
39 $TotalBackupSizeGB = ConvertTo-GB -bytes $TotalBackupSizeBytes
40
41 # Print the total size of the backup files for this date
42 Write-Output "The total size of the backup files for the date $DateString is $TotalBackupSizeGB."
43}
44

 

3 comments

Chris.Childerhose
Forum|alt.badge.img+21

Wow two to add in one day!  Thanks for this one as well.  πŸ˜Ž


Scott
Forum|alt.badge.img+9
  • Author
  • Veeam Legend
  • 1110 comments
  • July 17, 2023
Chris.Childerhose wrote:

Wow two to add in one day!  Thanks for this one as well.  πŸ˜Ž

I jumped the gun on the first one a bit :). After modifying the date a few times I realized just showing the last 2 weeks was the way to go. 

 

 

 

 

 

 

 


Chris.Childerhose
Forum|alt.badge.img+21
Scott wrote:
Chris.Childerhose wrote:

Wow two to add in one day!  Thanks for this one as well.  πŸ˜Ž

I jumped the gun on the first one a bit :). After modifying the date a few times I realized just showing the last 2 weeks was the way to go. 

 

 

 

 

 

 

 

Ah.  But even this one like you mentioned changing the date you can make it longer/shorter window which is great.


Comment