storage-legacy-clean.ps1 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # 清理旧版存储目录(Windows PowerShell)。确认新布局已经验证通过后再执行。
  2. # 用法:
  3. # powershell -ExecutionPolicy Bypass -File deploy/storage-legacy-clean.ps1
  4. # powershell -ExecutionPolicy Bypass -File deploy/storage-legacy-clean.ps1 -Confirm
  5. param(
  6. [switch]$Confirm
  7. )
  8. $ErrorActionPreference = "Stop"
  9. $Root = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
  10. $Base = Join-Path $Root "qingjian"
  11. $Targets = @(
  12. (Join-Path $Base "workspace"),
  13. (Join-Path $Base "chat-attachments"),
  14. (Join-Path $Base "agent"),
  15. (Join-Path $Base "tmp"),
  16. (Join-Path $Base "graph_his"),
  17. (Join-Path $Root ".agentscope"),
  18. (Join-Path $Root "data\files"),
  19. (Join-Path $Root "data\native"),
  20. (Join-Path $Root "ai-server\QingJian"),
  21. (Join-Path $Root "ai-server\data"),
  22. (Join-Path $Root "ai-server\.agentscope")
  23. )
  24. Write-Host "将清理以下旧目录:"
  25. foreach ($t in $Targets) {
  26. if (Test-Path $t) {
  27. $size = (Get-ChildItem -LiteralPath $t -Recurse -Force -ErrorAction SilentlyContinue |
  28. Measure-Object -Property Length -Sum).Sum
  29. $mb = if ($size) { [math]::Round($size / 1MB, 1) } else { 0 }
  30. Write-Host " - $t (${mb} MB)"
  31. }
  32. }
  33. if (-not $Confirm) {
  34. Write-Host ""
  35. Write-Host "未删除任何文件。确认无误后追加 -Confirm 执行。"
  36. exit 0
  37. }
  38. foreach ($t in $Targets) {
  39. if (Test-Path $t) {
  40. Write-Host "删除 $t"
  41. Remove-Item -LiteralPath $t -Recurse -Force
  42. }
  43. }
  44. Write-Host "清理完成。业务数据保留在 $Base\data"