恢复这件事只有两种状态:有备份,十分钟搞定;没备份,从头配一遍。演练的意义是让你在还没出事的时候确认自己处于第一种。
备份(现在就做,一分钟)
cd ~/.dsh && tar -czf ~/dsh-profiles-$(date +%Y%m%d).tgz profiles ls -lh ~/dsh-profiles-*.tgz
profiles只要1 MB量级,没有理由不备。
演练:故意改坏一处,再恢复
- 先确认现在能跑:
dsh --profile web --dump-config | head - 故意加一行非法内容到
~/.dsh/profiles/web/cordis.patch.yml,确认启动报错。这一步是为了知道「坏了长什么样」。 - 解压备份覆盖回去。
- 再跑一次dump,确认恢复正常。
cd ~/.dsh && tar -xzf ~/dsh-profiles-20261114.tgz && dsh --profile web --dump-config | head
注意:cordis.yml 不是该改的那个文件
本机 cordis.yml 的顶部注释写得很明确:
# dsh profile root — an empty entry list. The tree is composed as patches: # each bundle in package.json's dsh.profile.bundles, then cordis.patch.yml, then any # --patch overlays. Edit cordis.patch.yml, not this file. []
合成顺序是:package.json 里的bundles → cordis.patch.yml → 命令行 --patch。所以改 cordis.yml 基本等于白改——它会被后面的层盖住,而你还以为自己的配置生效了。
这条是恢复演练里最容易踩的坑:你以为改了配置,其实改的那份每次启动都重写或被覆盖。恢复之后先确认你改的是patch层。
没备份怎么救
dsh --dump-default-config能打出不带用户层的默认树,对照它找出你多改了什么。- 照上一页重新生成一份profile:
cp -r另一个还能跑的profile,再按记忆逐条加回改动。 - bundles列表在
package.json里,重建profile时它是最容易漏的一项。