gongxiangp2/scripts/migrate-old-storage-cautious.sh

81 lines
2.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 谨慎的迁移计划脚本
# 分阶段执行迁移,每阶段验证后再继续
set -e # 遇到错误立即退出
echo "============================================================"
echo "旧存储桶迁移 - 谨慎计划"
echo "============================================================"
echo ""
# 设置环境变量
export DATABASE_URL="postgresql://gongxiangpan:gongxiangpan123@192.168.58.20:5432/lobechat"
# 阶段1: 试运行(5个素材)
echo "阶段1: 试运行(5个素材)"
echo "----------------------------------------"
npx tsx scripts/migrate-old-storage-to-new.ts --dry-run --limit 5
echo ""
read -p "试运行完成,是否继续?(y/n) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "已取消"
exit 1
fi
# 阶段2: 小批量测试(5个素材)
echo ""
echo "阶段2: 小批量测试迁移(5个素材)"
echo "----------------------------------------"
npx tsx scripts/migrate-old-storage-to-new.ts --limit 5
echo ""
read -p "小批量测试完成,请验证迁移结果。是否继续下一批?(y/n) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "已暂停,可以稍后继续"
exit 0
fi
# 阶段3: 中等批量(20个素材)
echo ""
echo "阶段3: 中等批量迁移(20个素材)"
echo "----------------------------------------"
npx tsx scripts/migrate-old-storage-to-new.ts --limit 20
echo ""
read -p "中等批量完成,请验证迁移结果。是否继续下一批?(y/n) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "已暂停,可以稍后继续"
exit 0
fi
# 阶段4: 大批量(50个素材)
echo ""
echo "阶段4: 大批量迁移(50个素材)"
echo "----------------------------------------"
npx tsx scripts/migrate-old-storage-to-new.ts --limit 50
echo ""
read -p "大批量完成,请验证迁移结果。是否继续全量迁移?(y/n) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "已暂停,可以稍后继续"
exit 0
fi
# 阶段5: 全量迁移(剩余所有)
echo ""
echo "阶段5: 全量迁移(剩余所有素材)"
echo "----------------------------------------"
npx tsx scripts/migrate-old-storage-to-new.ts
echo ""
echo "============================================================"
echo "迁移完成!"
echo "============================================================"
echo "⚠️ 重要提示:"
echo " - 旧存储桶中的文件未删除(作为备份)"
echo " - 请验证迁移结果"
echo " - 确认无误后,可以手动清理旧存储桶(可选)"
echo ""