Add Spain all-in-one export upload script
This commit is contained in:
@@ -26,6 +26,24 @@ $outputDirectory = Join-Path $BaseDirectory "out"
|
||||
$logDirectory = Join-Path $BaseDirectory "logs"
|
||||
New-Item -ItemType Directory -Force -Path $outputDirectory, $logDirectory | Out-Null
|
||||
|
||||
if (-not (Get-Command $RcloneExe -ErrorAction SilentlyContinue)) {
|
||||
throw "rclone executable not found: $RcloneExe"
|
||||
}
|
||||
|
||||
$target = "${RcloneRemote}:$RcloneTarget"
|
||||
$rcloneLog = Join-Path $logDirectory ("rclone-spain-" + (Get-Date -Format "yyyyMMdd") + ".log")
|
||||
|
||||
Write-Host "Checking SharePoint target with rclone: $target"
|
||||
& $RcloneExe mkdir $target --log-file $rcloneLog --log-level INFO
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Could not create/check SharePoint target '$target'. rclone exit code $LASTEXITCODE. Log: $rcloneLog"
|
||||
}
|
||||
|
||||
& $RcloneExe lsf $target --max-depth 1 --log-file $rcloneLog --log-level INFO | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "SharePoint target '$target' is not reachable. rclone exit code $LASTEXITCODE. Log: $rcloneLog"
|
||||
}
|
||||
|
||||
$exportArgs = @(
|
||||
"-ServerInstance", $ServerInstance,
|
||||
"-Database", $Database,
|
||||
@@ -54,18 +72,35 @@ if ($null -eq $latestRun) {
|
||||
throw "No export run directory found in $outputDirectory"
|
||||
}
|
||||
|
||||
$rcloneLog = Join-Path $logDirectory ("rclone-spain-" + (Get-Date -Format "yyyyMMdd") + ".log")
|
||||
$target = "${RcloneRemote}:$RcloneTarget"
|
||||
$filesToUpload = Get-ChildItem -LiteralPath $latestRun.FullName -File |
|
||||
Where-Object { $_.Name -like "*.csv" -or $_.Name -like "*_summary.txt" }
|
||||
if ($filesToUpload.Count -eq 0) {
|
||||
throw "No CSV or summary files found for upload in $($latestRun.FullName)"
|
||||
}
|
||||
|
||||
Write-Host "Uploading $($filesToUpload.Count) file(s) to SharePoint target: $target"
|
||||
|
||||
& $RcloneExe copy $latestRun.FullName $target `
|
||||
--include "*.csv" `
|
||||
--include "*_summary.txt" `
|
||||
--verbose `
|
||||
--log-file $rcloneLog `
|
||||
--log-level INFO
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "rclone upload failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
|
||||
foreach ($file in $filesToUpload) {
|
||||
$uploadedMatch = & $RcloneExe lsf $target --files-only --include $file.Name --log-file $rcloneLog --log-level INFO
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Could not verify uploaded file '$($file.Name)' in '$target'. rclone exit code $LASTEXITCODE. Log: $rcloneLog"
|
||||
}
|
||||
|
||||
if (-not ($uploadedMatch | Where-Object { $_ -eq $file.Name })) {
|
||||
throw "Upload verification failed. File '$($file.Name)' was not listed in '$target'. Log: $rcloneLog"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Spain export and upload finished."
|
||||
Write-Host "Local export: $($latestRun.FullName)"
|
||||
Write-Host "SharePoint target: $target"
|
||||
|
||||
Reference in New Issue
Block a user