This commit is contained in:
DoTheEvo committed 2026-07-17 18:24:27 +02:00
1 parent c3cce07030
commit 3d17c77886
2 files changed
+62 -1

No files matched your search

@@ -0,0 +1,54 @@
$NasName = "NAS-2"
$Excluded = @("something1", "something2") # skip these shares
$env:KOPIA_CONFIG_PATH = "C:\Kopia\repository.config"
# Get list of shares from the NAS
$Shares = net view "\\$NasName" | ForEach-Object {
if ($_ -match '^(\S+)\s+Disk\s*$') {
$matches[1]
}
} | Where-Object { $_ -notin $Excluded }
# Get list of Kopia policies and their UNC paths
# Filters out the global policy which has an empty path.
$KopiaPolicyPaths = kopia policy list --json | ConvertFrom-Json | ForEach-Object { $_.target.path } | Where-Object { $_ }
Write-Host "====== checking for new shares to add ======"
Write-Host "..."
foreach ($Share in $Shares) {
$UncPath = "\\$NasName\$Share"
# Check whether share has a kopia policy defined
$HasPolicy = $KopiaPolicyPaths | Where-Object { $_ -ieq $UncPath }
if (-not $HasPolicy) {
Write-Host "$UncPath - creating a new policy"
# Temporarily relax EAP as Kopia writes information messages in to stderr
$prevEAP = $ErrorActionPreference
$ErrorActionPreference = "Continue"
# Kopia requires at least one flag explicitly defined
$output = kopia policy set $UncPath --keep-latest inherit 2>&1
$ErrorActionPreference = $prevEAP
# Exit code is the real success/failure signal not the stderr
# non-zero here means Kopia genuinely failed.
if ($LASTEXITCODE -ne 0) {
Write-Warning "Failed to set policy for $UncPath (exit code $LASTEXITCODE): $output"
}
}
}
Write-Host "..."
Write-Host "============== check done ================"
Write-Host ""
Write-Host "============= current policies ============="
kopia policy list --json | ConvertFrom-Json | ForEach-Object { $_.target.path } | Where-Object { $_ }
Write-Host ""
Write-Host "============= ignored shares ==============="
$Excluded | ForEach-Object { "\\$NasName\$_" }
@@ -1,4 +1,11 @@
kopia server start --insecure --config-file=C:\Kopia\repository.config --log-dir=C:\Kopia\Kopia_Logs --address=127.0.0.1:51515 --server-username=admin --server-password=aaa --enable-actions
kopia server start ^
--config-file=C:\Kopia\repository.config ^
--insecure ^
--address=127.0.0.1:51515 ^
--server-username=admin --server-password=aaa ^
--log-dir=C:\Kopia\Kopia_Logs ^
--cache-directory=C:\Kopia\Kopia_Cache ^
--enable-actions
:: to have full functinality of a kopia server
:: replace the above command with the one below