Linux-based operating systems, if well configured, are really stable; however, since bad things can always happen, it is a good idea to regularly create backups. As we saw in previous articles, there are many types of backup, and many possible backup strategies which can be implemented on Linux, using free and open source software. In this article we focus on Timeshift, an application which allows us to create incremental backups of our Linux system. The tool is similar to the Apple Time Machine, and can work as a frontend for rsync or use the BTRFS filesystem snapshot feature under the hood.
In this tutorial we see how to install and configure Timeshift on Linux, and how to create incremental system backups.
In this tutorial you will learn:
- How to install and configure Timeshift
- How to create and explore snapshots manually
- How to restore a snapshot
|Category||Requirements, Conventions or Software Version Used|
|Conventions||# – requires given linux-commands to be executed with root privileges either directly as a root user or by use of
Timeshift is free and open source software (source code can be found on github) released under the LGPL-3.0 and GPL-3 licenses. The application is available in the official repositories of the major Linux distributions, therefore we can easily install it via our favorite package manager. To install the package on Fedora, for example, we can use
dnf, and run the following command:
$ sudo dnf install timeshift
On Debian and Ubuntu, instead, we can use the
aptwrapper to perform the same action:
$ sudo apt install timeshift
Once installed, Timeshift can be easily launched from our favorite desktop environment application menu, or straight from the command line. The first time we start the application, we are prompted to choose what kind of backend we want to use, between
Each snapshot type has its pro and cons. BTRFS-based snapshots are byte-for-byte copies of the original filesystem, and they are created and restored in no time by using the native snapshot feature of the BTRFS filesystem. One major drawback of BTRFS snapshots is that they cannot be saved on external disks or devices, therefore if the main disk fails, the snapshots are lost with it (in this sense, they are not a “proper” backup).
Rsync-based snapshots, on the other hand, are created by using the rsync application, and are based on the use of hard links, implementing a strategy similar to the one we talked about in this article about creating incremental backups. When the first system backup is created, all files are copied (full backup); subsequent backups, instead, will include only changed files. Snapshots created by using rsync can be copied on external devices formatted with a Linux filesystem.
For the sake of this tutorial, we will use rsync as Timeshift backend. We select the related option and click on the “Next” button.
The next step consists in choosing where Timeshift should save the created snapshots:
Snapshot will be kept inside the
/timeshift directory on the selected filesystem. Unfortunately, remote filesystem are not yet supported. Once we select the snapshots destination and click on the “Next” button again, we will be prompted to choose what kind of snapshots we want to take (Monthly, Weekly, Daily, Hourly, at Boot), and how many snapshots of a specific type should be kept:
By default the application is configured to create and keep 5 daily backups. Boot snapshots, if selected, are created on system boot. Snapshots can also be created “on demand”, whenever we choose to.
As a last step, we are prompted to choose whether users home directories should be included in the snapshots or not, and what kind of files should be included (hidden ones or all). By default home directories are not included in snapshots:
At this point we can click on Finish to start using the application. The snapshots will be created following the selected schedule.
Creating snapshots manually
Once we finish the first-launch configuration, we get access to the Timeshift main window:
Here we can perform a variety of actions. Should we decide to change some of the application settings, for example, we can just click on the “Settings” button in the main application menu. We can also decide to immediately create a snapshot, independently of the selected schedule. All we have to do, is to click on the “Create” button. As soon as we do, the snapshot creation will start:
Since this is the first snapshot which is created, all the system files are included in it, therefore the process will require some time. Once the snapshot is ready, it does appear in the list:
As we said before, snapshots are created inside the
/timeshift directory, in the filesystem we selected as destination, and are ordered depending on their type. In this case, for example, the snapshot has been saved inside the
To explore the files included in the snapshot, we can select it in the list and click on the “Browse” button. A file manager window will be opened displaying the included files. In the same way we can delete a snapshot by clicking on the “Delete” button and restore a snapshot by clicking on “Restore”.
Restoring a snapshot
To restore a snapshot, as we just said, all we have to do is to select the snapshot we want to restore from the list and click on the “Restore button”. As soon as we do, a new window is displayed. Here we can confirm the mapping between the snapshot and the system partitions.
The filesystems from which the snapshot was created are selected by default, so in the majority of cases, if you made no change to system partitions, nothing needs to be modified.
Here we also have the chance to reinstall and update the GRUB2 bootloader configuration and regenerate the distribution initramfs image by clicking on the “Bootloader Options” button. Those actions may be necessary in case we perform drastic actions, like, for example restoring a snapshot of a different distribution:
When ready, we can click on the “Next” button. At first, Timeshift will run rsync in “dry” mode (changes will not be performed, but just logged). A list of the files and actions involved in the snapshot restoration will be displayed:
In this case, for example, we can clearly see the files that would be newly created (
/here.log) and those who will just be restored on the destination. To proceed, we can click on the “Next” button again. A disclaimer will be displayed:
The system will be rebooted once the process is finished, so be sure to make the appropriate actions before proceeding.
In this tutorial we saw how to install and configure Timeshift on some of the most used Linux distributions. The application let us perform incremental system backup, so we can easily restore our system to a known good state if it breaks. We saw how to configure the application, how to schedule a system snapshot and how to perform a snapshot on demand. We also saw how to explore the files contained in a snapshot, and finally, how to restore one.