storage-legacy-clean.ps1 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 "ai-server\QingJian"),
  20. (Join-Path $Root "ai-server\data"),
  21. (Join-Path $Root "ai-server\.agentscope")
  22. )
  23. Write-Host "将清理以下旧目录:"
  24. foreach ($t in $Targets) {
  25. if (Test-Path $t) {
  26. $size = (Get-ChildItem -LiteralPath $t -Recurse -Force -ErrorAction SilentlyContinue |
  27. Measure-Object -Property Length -Sum).Sum
  28. $mb = if ($size) { [math]::Round($size / 1MB, 1) } else { 0 }
  29. Write-Host " - $t (${mb} MB)"
  30. }
  31. }
  32. if (-not $Confirm) {
  33. Write-Host ""
  34. Write-Host "未删除任何文件。确认无误后追加 -Confirm 执行。"
  35. exit 0
  36. }
  37. foreach ($t in $Targets) {
  38. if (Test-Path $t) {
  39. Write-Host "删除 $t"
  40. Remove-Item -LiteralPath $t -Recurse -Force
  41. }
  42. }
  43. Write-Host "清理完成。业务数据保留在 $Base\data"