things
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
# Set up your TrueNAS server details and API Key
|
||||
$TrueNASSource = "https://truenas3.kwyjibo.info"
|
||||
$APIKeySource = "1-JLgbBRp1c0xRlAi5237SFeb7LZnLT23k4K8u95ewqgvTDO8jauv5r6s2MIPH7GmW" # Replace with your actual API key
|
||||
|
||||
# Construct the full API URL
|
||||
$TrueNASSourceUrl = "$TrueNASSource$Endpoint"
|
||||
|
||||
# Set up the headers with the API Key for authentication
|
||||
$headers = @{
|
||||
"Authorization" = "Bearer $APIKeySource"
|
||||
"Content-Type" = "application/json"
|
||||
}
|
||||
|
||||
$Endpoint = "/api/v2.0/zfs/snapshot"
|
||||
$TrueNASSourceUrl = "$TrueNASSource$Endpoint"
|
||||
$SnapshotSplat = @{
|
||||
Uri = $TrueNASSourceUrl
|
||||
Headers = $headers
|
||||
Method = "Get"
|
||||
SkipCertificateCheck = $true
|
||||
}
|
||||
$Snapshots = Invoke-RestMethod @SnapshotSplat
|
||||
|
||||
|
||||
# report on snapshot sizes
|
||||
$Report =
|
||||
$Snapshots |
|
||||
ForEach-Object {
|
||||
[PSCustomObject]@{
|
||||
Dataset = $_.dataset
|
||||
|
||||
UsedGB = [math]::Round(
|
||||
[int64]$_.properties.logicalreferenced.rawvalue / 1GB, 2
|
||||
)
|
||||
|
||||
Creation = [DateTimeOffset]::FromUnixTimeSeconds(
|
||||
[int64]$_.properties.creation.rawvalue
|
||||
).LocalDateTime
|
||||
}
|
||||
} |
|
||||
Group-Object Dataset | ForEach-Object {
|
||||
$snaps = $_.Group | Sort-Object Creation
|
||||
$newest = $snaps[-1]
|
||||
|
||||
[PSCustomObject]@{
|
||||
Dataset = $_.Name
|
||||
|
||||
NewestSnapshotDate = $newest.Creation
|
||||
NewestSnapshotGB = $newest.UsedGB
|
||||
|
||||
SmallestSnapshotGB = ($snaps | Measure-Object UsedGB -Minimum).Minimum
|
||||
LargestSnapshotGB = ($snaps | Measure-Object UsedGB -Maximum).Maximum
|
||||
|
||||
SnapshotCount = $snaps.Count
|
||||
SnapshotOverhead = ($snaps | Measure-Object UsedGB -Maximum).Maximum - $newest.UsedGB
|
||||
}
|
||||
}
|
||||
|
||||
$Report | Where-Object { $_.Dataset -NotLike "*boot*" -and $_.Dataset -notlike "*apps*" } | Format-Table -AutoSize
|
||||
|
||||
$Report | Where-Object { $_.Dataset -Like "*Delta*" } | Measure-Object -Property SnapshotOverhead -Sum
|
||||
|
||||
$DatasetRoots = @($Report | ForEach-Object { $_.Dataset.split('/')[0] } | Where-Object { $_ -notlike "*boot*" -and $_ -notlike "*nvme*" -and $_ -notlike "*Sidewinder*" } | Select-Object -Unique )
|
||||
|
||||
$DatasetRoots | ForEach-Object {
|
||||
$_;
|
||||
$Report | Where-Object { $_.Dataset -like "*$_*" }
|
||||
}
|
||||
Reference in New Issue
Block a user