Loading...
Loading...
macOS 系统迁移助手 — 两阶段:先在旧系统采集清单(JSON),再在新系统还原。 Use when user mentions: 系统迁移、换电脑、新装系统、Time Machine 恢复、 数据迁移、重装系统、migration、setup new mac、restore from backup、备份系统。 自动检测当前是旧系统(采集模式)还是新系统(还原模式)。 前置:先做一次 Time Machine 全量备份;唯一软件依赖是 Homebrew。
npx skill4agent add ttfake92-lab/skills macos-migration没有 Time Machine 全量备份,就不要开始迁移。
ls ~/migration-manifest.json 2>/dev/null| 条件 | 模式 |
|---|---|
| 无清单文件 | 采集模式(在旧系统上,生成清单) |
| 有清单文件 | 还原模式(在新系统上,读清单还原) |
which brew && brew --version || echo "NOT_INSTALLED"/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"eval "$(/opt/homebrew/bin/brew shellenv)"~/migration-manifest.jsonbrew list --formula
brew list --cask
brew tapls /Applications/
ls ~/Applications/ 2>/dev/nullmas list 2>/dev/null || echo "mas not installed"masbrew install masnpm ls -g --depth=0 2>/dev/nulluv tool list 2>/dev/nullpip list 2>/dev/null
pipx list 2>/dev/nullls ~/go/bin/ 2>/dev/nullls -la ~/.zshrc.zshenv.zprofile.bashrc.bash_profile.gitconfig.gitignore_global.ssh/.claude/.codex/.config/.cursor/.zed/.docker/.kube/.npm/.nvm/.bun/.cargo/.rustup/.SwitchHosts/.ollama/.syncthing/.ssh/.aws/.kube/"skipped_sensitive": [...]ls ~/Library/LaunchAgents/ls -d ~/*/ 2>/dev/null# 当前 shell 版本
zsh --version
# Homebrew 路径 / 版本管理器(nvm、fnm 等)配置
grep -iE 'brew|nvm|fnm' ~/.zshrc# 编辑器扩展
code --list-extensions 2>/dev/null
cursor --list-extensions 2>/dev/null
# 自购/自装字体
ls ~/Library/Fonts/ 2>/dev/null
# 定时任务
crontab -l 2>/dev/null
# 手动装到非 Homebrew 路径的命令行工具
ls /usr/local/bin/ 2>/dev/null
ls /opt/ 2>/dev/null系统偏好()量大且与机型强相关,不自动采集;如用户在意,在还原差异 报告里提醒手动核对(键盘、触控板、Dock、快捷键等)。defaults
~/migration-manifest.json{
"version": 1,
"captured_at": "2026-06-28T16:00:00+08:00",
"source_macos": "15.5",
"source_hostname": "old-macbook",
"homebrew": {
"taps": ["user/repo", "..."],
"formulas": ["git", "node@22", "..."],
"casks": ["1password", "docker-desktop", "..."]
},
"applications": {
"homebrew_casks": ["claude", "firefox", "..."],
"app_store": [{"id": 123456, "name": "App Name"}],
"manual": ["Final Cut Pro.app", "..."]
},
"package_managers": {
"npm_global": ["@anthropic-ai/claude-code", "..."],
"uv_tools": ["nano-pdf", "..."],
"pip_packages": ["package1", "..."],
"go_binaries": ["tool1", "..."]
},
"configs": {
"dotfiles": [".zshrc", ".gitconfig", ".ssh", "..."],
"config_dirs": [".claude", ".codex", ".config", ".docker", "..."],
"app_support_keys": ["Syncthing", "obs-studio", "..."]
},
"editor_extensions": {
"vscode": ["ms-python.python", "..."],
"cursor": ["..."]
},
"fonts": ["MyFont.otf", "..."],
"crontab": "<crontab -l 原文,无则空>",
"manual_bins": ["/usr/local/bin/foo", "/opt/bar", "..."],
"launch_agents": ["com.github.syncthing.plist", "..."],
"user_dirs": ["Projects", "Sites", "..."],
"shell": {
"shell": "zsh",
"brew_in_path": true,
"nvm_installed": true,
"custom_env_vars": {}
},
"skipped_sensitive": []
}✅ 采集完成!清单已保存到 ~/migration-manifest.json
采集内容:
- Homebrew: X taps, Y formulas, Z casks
- 应用: X 个 Homebrew, Y 个 App Store, Z 个手动安装
- npm 全局包: X 个
- 配置文件: X 个 dotfiles, Y 个配置目录
- 编辑器扩展: X 个 / 字体: Y 个 / 定时任务: 有/无
- 自启动服务: X 个
- 用户目录: X 个
- 跳过的敏感项: X 个(用户选择不采集)
⚠️ 若采集了 .ssh / dotfiles 中的凭据,清单与备份含私钥,传输存放注意不要外泄。
下一步:确认已有 Time Machine 全量备份,将 migration-manifest.json 复制到新系统,
再次运行此 skill。migration-manifest.jsonls ~/migration-manifest.json找不到 migration-manifest.json。
请将旧系统上采集的清单文件复制到新系统的 home 目录:
scp old-mac:~/migration-manifest.json ~/migration-manifest.json
或者手动指定路径。前提:第零步已确认 Homebrew 装好(需用户手动输密码安装)。装好之后这一步才能跑。
homebrew# 添加 taps(逐个)
brew tap <user>/<repo>
# 信任第三方 taps
brew trust <user>/<repo>
# 安装 formulas(批量,失败不回滚整批)
brew install <formula1> <formula2> ...
# 安装 casks(逐个,避免回滚)
for cask in <cask1> <cask2> ...; do
brew install --cask "$cask" 2>&1 | tail -3
donepackage_managers# npm
npm install -g <pkg1> <pkg2> ...
# uv
uv tool install <pkg1> <pkg2> ...
# pip(如果需要)
pip install <pkg1> <pkg2> ...
# go binaries
go install <pkg1>@latest <pkg2>@latest ...configsTM="<Time Machine 用户目录路径>"
LOCAL="/Users/<username>"
# dotfiles
rsync -av --ignore-existing "$TM/.zshrc" "$LOCAL/"
rsync -av --ignore-existing "$TM/.gitconfig" "$LOCAL/"
rsync -av --ignore-existing "$TM/.ssh/" "$LOCAL/.ssh/"
# 配置目录
for dir in .claude .codex .config .docker .SwitchHosts ...; do
rsync -av --ignore-existing "$TM/$dir/" "$LOCAL/$dir/"
done恢复后确认权限:.ssh/。 如无 Time Machine,提示用户提供配置文件的来源路径。chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_*
| 子目录 | 命令 | 说明 |
|---|---|---|
| Preferences | | 应用偏好设置 |
| Keychains | | 钥匙串 |
| Containers | | 沙盒应用数据 |
| Group Containers | | 共享容器 |
| 邮件数据 | |
| Safari | | 书签/历史 |
rsync 在 Time Machine APFS 快照上会报错误,Library 用io_read_flush。cp -rn
launch_agentslaunchctl load# 编辑器扩展(逐个装)
for ext in <清单 editor_extensions.vscode>; do code --install-extension "$ext"; done
# 字体
rsync -av --ignore-existing "$TM/Library/Fonts/" "$LOCAL/Library/Fonts/"
# 定时任务:先看新机器有没有现成的,再决定是否合并写入,避免覆盖
crontab -l 2>/dev/null、/usr/local/bin里的手动安装工具无法自动还原,列入 B7 差异报告提醒用户。/opt
## 还原差异报告
### ❌ 安装失败(需手动处理)
- docker-desktop: 需要 sudo → 手动执行 `brew install --cask docker-desktop`
- tailscale-app: 需要 sudo → 手动执行 `brew install --cask tailscale-app`
- android-platform-tools: 网络问题 → 稍后重试
### ⚠️ 清单中有但无 Homebrew cask
- Final Cut Pro: App Store 应用
- DaVinci Resolve Studio: 手动下载 → blackmagicdesign.com
### ℹ️ App Store 应用(需手动安装或用 mas)
- GarageBand
- Infuse
### 🔧 需手动核对(非软件)
- 系统偏好 defaults:键盘 / 触控板 / Dock / 快捷键
- /usr/local/bin、/opt 手动工具:<manual_bins 列表>
- 拒绝采集的敏感项:<skipped_sensitive 列表>brew bundlebrew bundle --file=Brewfilebrew bundleRefusing to load cask from untrusted tapbrew trust <user>/<repo>rsync -av --ignore-existingio_read_flushcp -rncp -rncp -rndocker-desktoptailscale-appadobe-creative-cloudbrew install node@22brew linkbrew link --overwrite node@22/Applications/brew list --cask--ignore-existing-nbrew bundlebrew listdu -sh