我正在为嵌入式linux系统制定一个更新协议,但是我想让用户可以选择回滚更新,如果它扰乱了他们的系统,特别是alpha/beta版本。因此,我发现cp命令选项可以自动备份覆盖的文件。
这个很好用!但是必须有一种简单的方法来用自动备份文件回滚这些更改,对吗?我不想强迫用户自己去查找所有修改过的文件的备份。
提前感谢您的帮助!
发布于 2022-05-18 10:18:30
如果您有两个并行文件系统树的空间,您可能有类似于/bin和/bin.old的东西。对所有顶级目录重复。
安装将是创建/bin.new、从活动系统复制、覆盖新文件、然后将/bin切换到/bin.old和/bin.new to /bin`等。回滚将是切换回。
# Prepare a new filesystem tree
#
rm -rf /*.new /*.old
for item in /*
do
cp -al "$item" "$item.new" # Links avoid using too much disk space
done
# Overlay. Because we linked in the previous step, we must remove
# (or rename) each file that we're going to change. Do not change
# or replace any file in situ
#
# If you have space for two full filesystem trees you could just copy
# instead of linking, which could simplify this update code section.
#
echo installation code goes here
# Switch over
#
OPATH="$PATH" PATH="/bin.old:/bin:/bin.new:$PATH"
for item in /*.new
do
live="${item%.new}"
mv -f "$live" "$live.old"
mv -f "$item" "$live"
done
# Post-installation steps (rebuild kernel links, etc.)
#
echo post-installation code goes here您可能希望在一个无法更新的地方拥有重要的系统二进制文件,这样回滚就不会被一个糟糕的shell所烧毁。但是,这有点像鸡和蛋的情况,在这种情况下,根据定义,您无法更新此代码。很棘手。
https://unix.stackexchange.com/questions/702994
复制相似问题