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
-
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.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.