Accessing the powerful Btrfs snapshot features with Snapper

Snap Stack

© Lead Image © ssilver,

© Lead Image © ssilver,

Article from Issue 176/2015

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.


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).

Figure 1: Btrfs-friendly commands like btrfs filesystem show work better in Snapper than conventional disk utilities like df -h.

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).

Figure 2: If necessary, you can create more configurations to grab snapshots of other areas of the filesystem.

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].

Figure 3: A graphical user interface in the YaST Control Center makes it easy to manage, compare, and restore snapshots as needed.

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).

Figure 4: The graphical interface makes it easy to compare two snapshots.
Figure 5: If necessary, you can create a snapshot manually.

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.

Figure 6: If you made a mistake in the configuration, you can pick up a working version of a file from a snapshot and drop it into the current system.

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

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Snapper

    Thanks to Btrfs snapshots, Snapper lets you restore a system to a previous state in case of failure.

  • Snapshot Tools

    Experts agree that you should keep a copy of your data, but restoring from incremental backups takes time and sometimes doesn't work as expected. Alternatively, you can capture your data in a snapshot. Read on for a review of some leading Linux snapshot tools.

  • On the DVD: openSUSE 12.1 & Fedora 16

    With this month’s DVD, you get to test the latest offerings from the openSUSE [1] and Fedora [2] projects

  • Btrfs

    The Btrfs filesystem offers advanced features such as RAID, subvolumes, snapshots, checksums, and transparent compression, but do desktop users really need all that power?

  • Timeshift

    Timeshift lets users easily create, manage, and restore system snapshots.

comments powered by Disqus
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.

Learn More