Ubuntu: How I do a system restore?



Question:

Problem I Faced

  • I installed something that crashed my Wifi drivers that I compiled earlier.
  • Un-installing the same package doesn't helped.
  • Finally, I re-compiled my wifi drivers and things are good.

My Question

But, is there anything like System Restore or System Rollback in Ubuntu/LinuxMint?

  • Is there anything that can undo an apt-get install package command?


Solution:1

The complement of apt-get install package is apt-get remove package. To remove all associated settings too, you need to run apt-get purge package.

Note that these commands rely on the uninstallation scripts provided with the package. All packages in the main repository I know of do their job of uninstalling very well. This may not be the case for third-party packages.

As for your driver issue, there are a few possibilities why installing a package broke your wireless driver:

  • The driver has a post-installation hook which is executed when a condition is met, e.g. kernel updates
  • The package overwrote a file that the wireless driver depended on
  • The package in question was a kernel update but the driver does not have a post-installation hook for recompiling the driver (most likely)

As for the "System rollback" / "System Restore" features, the closest feature you'll get is a system image using software like Clonezilla. Unfortunately, this cannot be done within a running system and must be performed from a Live CD.


Solution:2

There is a software for Linux called Timeshift exactly for this purpose. Using Timeshift you can take snapshots of your Linux system regularly and restore them whenever you need.

This software brings System Restore feature of Windows to your Linux distribution.

A short description from its official website:

TimeShift for Linux is a application that provides functionality similar to the System Restore feature in Windows and the Time Machine tool in Mac OS. TimeShift protects your system by taking incremental snapshots of the file system at regular intervals. These snapshots can be restored later to bring your system to the exact state it was in at the time when the snapshot was taken.

Snapshots are taken using rsync and hard-links. Common files are shared between snapshots which saves disk space. Each snapshot is a full system backup that can be browsed with a file manager.


Solution:3

Actually, there are few things in Ubuntu et al. that will allow you to roll-back changes. Brief below:

  1. /var/backups/dpkg.status.*: this directory keeps a set of log of the last system state prior to an install as follows; /var/backups/dpkg.status.0 is the most recent log prior to a state change (e.g. package install/remove/update ...etc); /var/backups/dpkg.status.?.gz are compressed, archived versions of the logs at various points in time, rotated monthly.
  2. /var/lib/dpkg/status: this is the current state of installed packages. Manually backing this up, or providing a logrotate script in /etc/logrotate.d will ensure schedule snapshots of your system state to your liking.
  3. Roll-back: the corner stone is your previous state /var/backups/dpkg.status.0. Here is a brief step-wise procedure to restore previous package state (note brief and not exhaustive).

    a. cp /var/backups/dpkg.status /var/lib/dpkg/status (will revert back the package state one version back).

    b. dpkg -l | grep ii (will give you a list of supposedly installed packages based on the rolled-back /var/lib/dpkg/status file achieved in step a. above).

    c. dpkg -l | grep ii | awk '{print "apt-get --reinstall -y install", $2}' > /tmp/reinstall && sh /tmp/reinstall (will create a simple one-liner shell script and runs that to reinstall packages determined to have been on the system prior to an apt-get operation)

    d. apt-get --reinstall install ucf (will take care of sanitising /etc config files et. al)

    e. Repeat step c. if/as necessary


With a minimal bit of luck, you should be OK.


Solution:4

There is no such feature in Ubuntu like "Restore to previous state" in Windows. You should have taken backup, to restore the machine to an earlier stage. Seriously I am also missing this feature. There are many tools but none of them work like Windows Restore point nor Macs Time Machine. Let's see if things get better in backup in Linux.


Solution:5

btrfs has/will have some nifty snapshot features that should be able to handle this sort of stuff. Just keep your data in one filesystem and your system in another, and use periodic (daily? weekly?) snapshots, then roll back whenever problems arise.


Solution:6

Apart from Timeshift and the /var logs mentioned, you can also use etckeeper to guard against ruining config files in your /etc directory and not having backups to restore to. It uses a VCS.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »