Skip to main content

Timeshift

IMPORTANT: Timeshift is not a backup tool! It only creates local snapshots of the system to roll back changes to the system. Do not rely on this mechanism to keep your data safe! Timeshift deletes the oldest snapshot when a new one is created and the maximum number of snapshots is reached. Furthermore, if the underlying file system is corrupted, the snapshots will be, too! Use a proper backup tool to keep your data safe on external data storage!

Timeshift helps create incremental snapshots of the file system at regular intervals, which can then be restored at a later date to undo all changes to the system.

It supports rsync snapshots for all filesystems, and uses the built-in snapshot features for Btrfs drives configured to use the @ and @home subvolume layout for root and home directories respectively.

Installation

Timeshift is available from the Arch repos. It uses cron to make regularly scheduled backups. Install Timeshift with a cron daemon, e.g. cronie:

pacman -S timeshift cronie

Start and enable the cron scheduler for Timeshift to take regular snapshots:

sudo systemctl enable --now cronie

Finally, start Timeshift and complete the first time setup.

Automatic snapshots on system changes

In addition to Timeshift's periodic spanshots, timeshift-autosnap provides a pacman hook to create a manual snapshot every time packages are installed, upgraded or removed.

Install timeshift-autosnap from the AUR:

yay -S timeshift-autosnap

By default timeshift-autosnap only keeps 3 snapshots. To change this, edit /etc/timeshift-autosnap.conf and either set deleteSnapshots to false to never delete any snapshots or increase the number of maxSnapshots:

skipAutosnap=false
deleteSnapshots=true
maxSnapshots=7
updateGrub=true
snapshotDescription={timeshift-autosnap} {created before upgrade}

Prevent excessive snapshotting when using yay

By default, when installing or updating multiple packages from the AUR, yay first builds a package and immediately calls pacman to install it, before building and installing the next one on its list. This also means that the timeshift-autosnap hook is triggered for each individual AUR package built by yay, including dependencies also installed from the AUR.

This can have undesireable side-effects:

  • yay will cause timeshift-autosnap to reach the maxSnapshots limit very quickly when installing multiple packages from the AUR, leaving you with snapshots with little to no meaningful changes between them
  • if deleteSnapshots is set to false the amount of snapshots might quickly exhaust the usable space on the drive

To prevent this it is recommended to configure yay to:

  1. not remove make dependencies after successfully built packages are installed
  2. build all AUR packages first, install them all later
  3. install AUR packages together with regular repo packages

By calling yay with the --save parameter, any options passed to it will be saved in a configuration file, e.g.:

yay --noremovemake --batchinstall --combinedupgrade --save  

Next time you use yay to install, upgrade or remove packages it will read the generated config file at ~/.config/yay/config.json and apply the options automatically without having to specify them during use.