deployment-rollback

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Deployment Rollback Skill

部署回滚Skill

Quick Rollback via Vercel

通过Vercel快速回滚

Using Vercel Dashboard

使用Vercel控制台

  1. Go to Vercel Dashboard → Project → Deployments
  2. Find the previous working deployment
  3. Click the three dots menu → "Promote to Production"
  1. 进入Vercel控制台 → 项目 → 部署记录
  2. 找到之前可正常运行的部署版本
  3. 点击三点菜单 → "Promote to Production(推广至生产环境)"

Using Vercel CLI

使用Vercel CLI

bash
undefined
bash
undefined

List recent deployments

列出近期部署记录

vercel list
vercel list

Promote a specific deployment to production

将指定部署版本推广至生产环境

vercel promote <deployment-url>
vercel promote <deployment-url>

Or rollback to previous production deployment

或回滚至之前的生产环境部署版本

vercel rollback
undefined
vercel rollback
undefined

Database Rollback

数据库回滚

bash
undefined
bash
undefined

Rollback last migration

回滚上一次迁移

pnpm -F @sgcarstrends/database db:rollback
pnpm -F @sgcarstrends/database db:rollback

Rollback to specific migration

回滚至指定迁移版本

pnpm -F @sgcarstrends/database db:rollback --to 20240115_initial
pnpm -F @sgcarstrends/database db:rollback --to 20240115_initial

Restore from backup

从备份恢复

pg_dump $DATABASE_URL > backup-pre-deploy.sql # Before deploy psql $DATABASE_URL < backup-pre-deploy.sql # Restore if needed
undefined
pg_dump $DATABASE_URL > backup-pre-deploy.sql # 部署前执行 psql $DATABASE_URL < backup-pre-deploy.sql # 必要时恢复
undefined

Git-Based Rollback

基于Git的回滚

bash
undefined
bash
undefined

Revert specific commit

撤销指定提交

git revert <commit-hash> git push origin main # Triggers Vercel redeploy
git revert <commit-hash> git push origin main # 触发Vercel重新部署

Create rollback branch

创建回滚分支

git checkout -b rollback/v1.1.0 git reset --hard v1.1.0 git push origin rollback/v1.1.0 gh pr create --title "Rollback to v1.1.0" --body "Emergency rollback"
undefined
git checkout -b rollback/v1.1.0 git reset --hard v1.1.0 git push origin rollback/v1.1.0 gh pr create --title "Rollback to v1.1.0" --body "Emergency rollback"
undefined

Cache Invalidation

缓存失效处理

bash
undefined
bash
undefined

Revalidate Next.js cache

重新验证Next.js缓存

Clear Redis cache

清空Redis缓存

redis-cli -h $REDIS_HOST FLUSHALL
undefined
redis-cli -h $REDIS_HOST FLUSHALL
undefined

Health Checks During Rollback

回滚期间的健康检查

bash
curl -f https://sgcarstrends.com || echo "Web unhealthy"
psql $DATABASE_URL -c "SELECT 1" || echo "Database unreachable"
bash
curl -f https://sgcarstrends.com || echo "Web unhealthy"
psql $DATABASE_URL -c "SELECT 1" || echo "Database unreachable"

Rollback Checklist

回滚检查清单

Pre-Rollback:
  • Identify issue and severity
  • Determine scope (full/partial)
  • Check backup availability
  • Notify team
During:
  • Rollback via Vercel dashboard or CLI
  • Rollback database if needed
  • Clear caches
  • Verify health checks
  • Run smoke tests
Post:
  • Monitor error rates in Vercel dashboard
  • Verify functionality restored
  • Document what happened
  • Create postmortem
回滚前:
  • 确定问题及严重程度
  • 确定影响范围(完全/部分)
  • 检查备份是否可用
  • 通知团队成员
回滚中:
  • 通过Vercel控制台或CLI执行回滚
  • 必要时回滚数据库
  • 清空缓存
  • 验证健康检查结果
  • 运行冒烟测试
回滚后:
  • 在Vercel控制台监控错误率
  • 验证功能是否恢复正常
  • 记录事件详情
  • 编写事后分析报告

Common Scenarios

常见场景

Critical Bug:
bash
vercel rollback
curl https://sgcarstrends.com/api/health
Database Migration Failure:
bash
pnpm -F @sgcarstrends/database db:rollback
git revert HEAD
git push origin main
严重漏洞:
bash
vercel rollback
curl https://sgcarstrends.com/api/health
数据库迁移失败:
bash
pnpm -F @sgcarstrends/database db:rollback
git revert HEAD
git push origin main

Troubleshooting

问题排查

Rollback deployment not working:
bash
undefined
部署回滚失败:
bash
undefined

Force redeploy from known good commit

从已知正常的提交强制重新部署

git checkout v1.1.0 vercel --prod

**Database schema mismatch:**
```bash
pnpm -F @sgcarstrends/database db:rollback
git checkout v1.1.0 vercel --prod

**数据库架构不匹配:**
```bash
pnpm -F @sgcarstrends/database db:rollback

Or restore backup: psql $DATABASE_URL < backup-pre-deploy.sql

或恢复备份:psql $DATABASE_URL < backup-pre-deploy.sql

undefined
undefined

Best Practices

最佳实践

  1. Always Backup: Create database backups before major deployments
  2. Test Rollback: Practice rollback procedures in preview deployments
  3. Feature Flags: Use for quick feature disabling without rollback
  4. Monitor Closely: Watch Vercel analytics during and after rollback
  5. Document Everything: Record what happened and why
  1. 始终备份:在重大部署前创建数据库备份
  2. 测试回滚:在预览部署环境中演练回滚流程
  3. 功能开关:使用功能开关快速禁用功能,无需执行回滚
  4. 密切监控:回滚期间及之后关注Vercel分析数据
  5. 完整记录:记录事件发生的经过及原因

References

参考资料