Merge pull request #108 from innovara/metered-check

Add feature to control backups on metered connections
This commit is contained in:
Kevin Woley
2025-01-27 15:12:00 -08:00
committed by GitHub
2 changed files with 14 additions and 0 deletions

View File

@@ -442,6 +442,10 @@ function Invoke-ConnectivityCheck {
"[[Internet]] Waiting for connection to repository ($repository_host)... $sleep_count" | Out-File -Append $SuccessLog
Start-Sleep 30
}
elseif((-not ([String]::IsNullOrEmpty($BackupOnMeteredNetwork)) -or $BackupOnMeteredNetwork)) -and Invoke-MeteredCheck)) {
"[[Internet]] Waiting for an unmetered network connection... $sleep_count" | Out-File -Append $SuccessLog
Start-Sleep 30
}
else {
return $true
}
@@ -449,6 +453,15 @@ function Invoke-ConnectivityCheck {
}
}
# check if on metered network
function Invoke-MeteredCheck {
[void][Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime]
$cost = [Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile().GetConnectionCost()
$cost.ApproachingDataLimit -or $cost.OverDataLimit -or $cost.Roaming -or $cost.BackgroundDataUsageRestricted -or ($cost.NetworkCostType -ne "Unrestricted")
}
# check previous logs
function Invoke-HistoryCheck {
Param($SuccessLog, $ErrorLog, $Action)

View File

@@ -3,6 +3,7 @@ $InstallPath = "C:\restic"
$ExeName = "restic.exe"
$GlobalParameters = @()
$LogRetentionDays = 30
$BackupOnMeteredNetwork = $false
$InternetTestAttempts = 10
$GlobalRetryAttempts = 4