gongxiangp2/scripts/check-prod-uploads-all.ps1

72 lines
2.4 KiB
PowerShell

# 检查生产服务器上所有缺失的文件是否都在本地 uploads 目录中
param(
[string]$ServerIP = '192.168.58.20',
[string]$ServerUser = 'root',
[string]$UploadsPath = '/mnt/PoolOne/apps/youyidian-3d/uploads'
)
Write-Host "==== 检查生产服务器上所有缺失的文件 ====" -ForegroundColor Cyan
Write-Host "服务器: $ServerIP" -ForegroundColor Yellow
Write-Host "路径: $UploadsPath" -ForegroundColor Yellow
Write-Host ""
# 读取缺失文件列表
$missingFileList = "missing-video-files.txt"
if (-not (Test-Path $missingFileList)) {
Write-Host "❌ 文件列表不存在: $missingFileList" -ForegroundColor Red
Write-Host " 请先运行: npx ts-node --transpile-only scripts/generate-missing-file-list.ts" -ForegroundColor Yellow
exit 1
}
$files = Get-Content $missingFileList
$totalFiles = $files.Count
Write-Host "共需要检查 $totalFiles 个文件" -ForegroundColor Yellow
Write-Host ""
# 检查每个文件
$foundCount = 0
$notFoundCount = 0
$notFoundFiles = @()
$progress = 0
foreach ($fileName in $files) {
$progress++
if ($progress % 10 -eq 0) {
Write-Host "检查进度: $progress / $totalFiles" -ForegroundColor Gray
}
$remoteFile = "$UploadsPath/$fileName"
$checkCmd = "test -f '$remoteFile' && echo 'EXISTS' || echo 'NOT_EXISTS'"
$result = ssh "${ServerUser}@${ServerIP}" $checkCmd
if ($result -match 'EXISTS') {
$foundCount++
} else {
$notFoundCount++
$notFoundFiles += $fileName
}
}
Write-Host ""
Write-Host "==== 检查结果 ====" -ForegroundColor Cyan
Write-Host " 在生产服务器本地找到: $foundCount 个" -ForegroundColor Green
Write-Host " 在生产服务器本地未找到: $notFoundCount 个" -ForegroundColor Red
if ($notFoundCount -gt 0) {
Write-Host ""
Write-Host "未找到的文件(前 20 个):" -ForegroundColor Yellow
$notFoundFiles[0..19] | ForEach-Object { Write-Host " - $_" -ForegroundColor Red }
if ($notFoundFiles.Count -gt 20) {
Write-Host " ... 还有 $($notFoundFiles.Count - 20) 个" -ForegroundColor Gray
}
Write-Host ""
Write-Host "💡 这些文件可能还在 MinIO 中,需要从 MinIO 下载到生产服务器的本地 uploads 目录" -ForegroundColor Yellow
} else {
Write-Host ""
Write-Host "✅ 所有文件都在生产服务器的本地 uploads 目录中!" -ForegroundColor Green
}