Skip to main content

Get Daily backup size for previous 2 weeks.


Scott
Forum|alt.badge.img+8
  • Veeam Legend
  • 993 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.

 

# Location of the Veeam backup folder
$BackupFolderPath = "f:\Backups"

# Start and end dates
$EndDate = Get-Date
$StartDate = $EndDate.AddDays(-14)

# Function to convert bytes to GB
function ConvertTo-GB {
    param (
        [Parameter(Mandatory=$true)]
        [int64]
        $bytes
    )
    return "{0:N2}" -f ($bytes / 1GB) + " GB"
}

# Go through each day from the start date to the end date
for ($Date = $StartDate; $Date -le $EndDate; $Date = $Date.AddDays(1)) {
    # Date in the format 'yyyy-MM-dd'
    $DateString = $Date.ToString('yyyy-MM-dd')

    # Get all backup files for this date
    $BackupFiles = Get-ChildItem -Path $BackupFolderPath -Recurse -Filter "*$DateString*"

    # If there's no backup file for this date, continue to the next date
    if ($BackupFiles -eq $null) {
        Write-Output "No backup files for the date $DateString were found."
        continue
    }

    # Sum up the sizes of all backup files for this date
    $TotalBackupSizeBytes = 0
    foreach ($BackupFile in $BackupFiles) {
        $TotalBackupSizeBytes += (Get-Item $BackupFile.FullName).Length
    }

    # Convert bytes to GB
    $TotalBackupSizeGB = ConvertTo-GB -bytes $TotalBackupSizeBytes

    # Print the total size of the backup files for this date
    Write-Output "The total size of the backup files for the date $DateString is $TotalBackupSizeGB."
}

 

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+8
  • Author
  • Veeam Legend
  • 993 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.