我刚刚删除了“/bin”。最好的恢复方法是什么?

Tom*_*nal 10 linux ubuntu

我只是跑了(不是故意的!)rm -rf /bin

我已经关闭了计算机并正在使用 Finnix 尝试从中恢复。我已经成功安装了驱动器,并确认,是的,整个/bin文件夹都被删除了。

是否可以在不重新安装操作系统的情况下从中恢复?

我想我可以设置一个具有相同操作系统和架构(Ubuntu Server 11.10 alpha 版本,x86)的 VM 并安装我在服务器上安装的所有软件包,然后只需复制/bin文件夹。

这会起作用吗?我最好重新开始吗?

wom*_*ble 15

In general, I'd lean towards a reinstall (from the backups you are absolutely supposed to have). But I'm feeling hackish, so here's another way (assuming that your system is mounted under /target):

  1. Get a list of all the installed packages that have files in /bin:

    grep ^/bin/ /target/var/lib/dpkg/info/*.list | sed 's%^.*/\([^/\.]*\).list%\1%' >/tmp/pkglist
    
    Run Code Online (Sandbox Code Playgroud)

    (On my Debian Squeeze system that's a total of 34 packages, pretty much all of which are core)

  2. Download each of those packages (I couldn't be bothered to script this bit, so just hit up packages.ubuntu.com and download them into somewhere under /target). If you're lucky some of the packages might still be floating around in /target/var/cache/apt/archives.

  3. For each package, run /target/usr/bin/dpkg -x <package> /target. I'm fairly certain dpkg is all self-contained these days, and shouldn't call out to anything in /bin itself.

Once you've got the system back on it's feet, you should make sure and run an apt-get --reinstall install <all the packages from step 1>, because (since you're running a pre-release, which Sysadmin Cat says is a no-no on production systems) the versions of the packages you just extracted are likely to be different from those that were on the system before, and you'll want to make sure the system knows exactly what's what.


hmo*_*liu 5

虽然您的策略可能有效(很有可能,如果您复制回 bin 目录后,您对系统中的所有软件包执行 apt-get 重新安装,则更多),但将来可能会产生问题,因为您可能会得到不稳定的服务器。

如果这发生在我身上,我会重新安装并从每日备份中恢复。你有一个每日备份 - 一个灾难恢复计划 - 不是吗?

如果您没有灾难恢复计划,我建议您备份所有配置文件和要保留的数据,然后重新安装。这样你就可以确定你会再次以稳定的服务器结束。