Accessing the powerful Btrfs snapshot features with Snapper
Snap Stack
Snapper lets you restore a system to its previous state – with a little help from Btrfs snapshots.
The openSUSE project believes in the Btrfs filesystem [1]. Btrfs has been the filesystem for the root partition since openSUSE 13.2 and version 12 of SUSE Linux Enterprise Server (SLES).
Work on the Btrfs filesystem has been going on for about eight years. Btrfs, like ZFS [2], relies on functions that are not usually included in a filesystem's repertoire. In addition to an extended storage area, Btrfs includes support for RAID 0, 1, 5, 6, and 10, as well as snapshots, subvolumes, and the ability to defragment partitions during operation. You can even convert ext3/4 partitions to Btrfs, after creating a backup, using the btrfs-convert
command from the Btrfs-tools package.
A tool called Snapper leverages the powers of Btrfs to provide what the developers call "the ultimate snapshot tool for Linux." Snapper offers a variety of convenient features for recording the system state. According to the Snapper portal at the openSUSE site, "Apart from the obvious creation and deletion of snapshots, Snapper can compare snapshots and revert differences between snapshots. In simple terms, this capability allows root and non-root users to view older versions of files and revert changes."
To find out if Snapper lives up to the promises of its developers, I tried it with openSUSE 13.2, which was released in early November 2014. When you work with Btrfs, it is important to work with the latest kernel, so I updated the kernel from version 3.16.7 to 3.19.1, along with updating the complete system.
SUSE developer Arvin Schnell was the lead developer on Snapper, which makes openSUSE a good option for these tests; however, you will also find Snapper in the archives of other distributions, such as Arch [3], Debian, and Ubuntu.
Be aware that different distributions and developers have different opinions regarding the readiness of the fledgling Btrfs. Btrfs developer Chris Mason, who uses Btrfs extensively for his employer Facebook, says the filesystem is very much ready for production use. Btrfs is still new, however, so it might pay to be cautious in some environments. If you're thinking about rolling out Snapper in a production setting, it makes sense to start with a test system.
Configuration
Installing openSUSE automatically sets up Snapper for the root partition. In this state, Snapper creates a snapshot before and after each action with the YaST configuration tool or the Zypper package manager. It is also possible, to use a timeline to create hourly snapshots. Snapper deletes most snapshots according to a predefined schedule, but it keeps some by default.
If you leave the default settings in the /etc/snapper/configs/root
file, the snapshots will quickly consume a huge amount of space. A root partition, which can normally make do with 30GB, will need between 100 and 300GB of disk space for snapshots, depending on the planned Snapper configuration.
Be sure to use the command
btrfs filesystem show
for obtaining filesystem information, rather than classic commands such as df
-h
or du
. (One of the annoying things about Btrfs is its lack of support for traditional command-line utilities (Figure 1).
If you want to use Snapper for the home partition, you need to convert the filesystem from XFS to Btrfs during installation. If home
remains on the root partition, Snapper will not cover it.
After the kernel update (Listing 1), but before you update the system with YaST or Zypper, you should edit the /etc/snapper/configs/root
file. This file contains settings for creating and deleting snapshots. On a desktop system, you might want to modify some of the default values. Listing 2 shows some examples of possible changes. The man page for snapper-configs
offers further insights [4]. For a detailed list of parameters, see the SUSE documentation [5].
Listing 1
Updating the Kernel
Listing 2
Changes for Snapshot Settings
If you want to create snapshots of the home partition, create the corresponding configuration using the command
sudo snapper -c home create-config /home
and then edit the configuration settings as necessary. Run
sudo snapper list-configs
to see whether the system has correctly incorporated both subvolumes. In addition to the entry for root
, you should now have an entry for home
(Figure 2).
The etc/snapper/filter
file lists files that the software never restores. Use this file to list the files you want to exclude from the restore process.
After you have finished with the configuration, you can control Snapper using the graphical interface (Figure 3). The Snapper man page discusses how to work with Snapper at the command line [6].
Operation via GUI
In the YaST Control Center in the Miscellaneous section below Software, you will find the Snapper module that gives you a graphical user interface for creating, viewing, comparing (Figure 4), restoring, or deleting snapshots. In addition to the automatic, cron-controlled snapshots, or snapshots generated during updates, you can, if necessary, create new snapshots manually using the Create button (Figure 5).
A manual snapshot is a good idea before any major change that will affect important files. If you experience problems later on, you can use Restore Selected to restore the state before the change was made [7] (Figure 6). If the system is in a state that no longer supports a rollback within the existing session, it is also possible to select a snapshot and boot from it during the restart using GRUB.
Ubuntu and Debian
I also tested Snapper with an early version of Ubuntu 15.04 "Vivid Vervet," which already has the Linux 3.19 kernel pre-installed. Ubuntu and Debian do not currently offer a graphical user interface for Snapper. The configuration is similar to the openSUSE configuration.
In the Universe repository, you will find three packages related to snapshots, which you will want to install depending on your objectives: The snapper package provides the basic functionality. If you want to create a snapshot every time a user logs in, you need libpam-snapper. The apt-btrfs-snapshot package ensures that the system creates a snapshot whenever it is updated via Apt.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.