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
-
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.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.