Using OpenSUSE's snapper on ArchLinux to manage btrfs snapshots

Today I created a PKGBUILD for OpenSUSE's snapper utility which allows creating and managing BTRFS snapshots. You can find it on AUR here.

Snapper is a quite handy tool to manage BTRFS snapshots. On OpenSUSE it comes with a YaST2 plugin, so it even has a GUI. On Arch you can still get the command line version though.

Configuration:

1. First create a .snapshots subvolume in the root of the subvolume you want to be snappered. E.g. for a /mnt/rootfs/arch-root subvolume:

btrfs subvolume create /mnt/rootfs/arch-root/.snapshots

2. Create a config based on the provided template

cd /etc/snapper
cp config-templates/default configs/root

3. Edit /etc/snapper/configs/root

# subvolume to snapshot
SUBVOLUME="/mnt/rootfs/arch-root"

4. Edit /etc/conf.d/snapper

SNAPPER_CONFIGS="root home"

Et voilà. That's it.

# snapper list-configs
Config | Subvolume            
-------+----------------------
root   | /mnt/rootfs/arch-root
home   | /mnt/rootfs/home

By default, snapper will take a snapshot every hour. To disable this, edit /etc/snapper/configs/ and set

TIMELINE_CREATE="no"

As snapshots cost almost no space at all, I'll keep it enabled. After some hours:

# snapper list
Type   | #  | Pre # | Date                        | Cleanup  | Description | Userdata
-------+----+-------+-----------------------------+----------+-------------+---------
single | 0  |       |                             |          | current     |         
single | 1  |       | Mi 01 Feb 2012 00:01:01 CET | timeline | timeline    |         
single | 2  |       | Mi 01 Feb 2012 01:01:01 CET | timeline | timeline    |         
single | 3  |       | Mi 01 Feb 2012 02:01:01 CET | timeline | timeline    |         
single | 4  |       | Mi 01 Feb 2012 03:01:01 CET | timeline | timeline    |         
single | 5  |       | Mi 01 Feb 2012 04:01:01 CET | timeline | timeline    |         
single | 6  |       | Mi 01 Feb 2012 05:01:01 CET | timeline | timeline    |         
single | 7  |       | Mi 01 Feb 2012 06:01:01 CET | timeline | timeline    |         
single | 8  |       | Mi 01 Feb 2012 07:01:01 CET | timeline | timeline    |         
single | 9  |       | Mi 01 Feb 2012 08:01:01 CET | timeline | timeline    |         
single | 10 |       | Mi 01 Feb 2012 09:01:01 CET | timeline | timeline    |         
single | 11 |       | Mi 01 Feb 2012 10:01:01 CET | timeline | timeline    |         
single | 12 |       | Mi 01 Feb 2012 11:01:01 CET | timeline | timeline    |         
single | 13 |       | Mi 01 Feb 2012 12:01:01 CET | timeline | timeline    |         

Basic Usage:

snapper will pick the "root" config by default. To see the "home" config, use:

snapper -c home list

You can compare snapshots with

snapper diff 12..13

By default, it will show chages from every file that changed. Also if you use snapper to revert changes, all files will get reverted. This is not desirable for systemfiles like /etc/mtab, logfiles and other dynamic files. This is where the filters feature comes in. To exclude everything in /var/log/, create the file /etc/snapper/filters/logfiles.txt

/var/log/*

I use these excludes for now:

/etc/mtab
/var/log/*
/var/tmp/*
/var/spool/mail/*
/var/lib/postgres/data/*
*/.bash_history

Help

Snapper includes manpages. See

man snapper
man snapper-configs

Hints (updated 2013-10-27)

After a year of snapper usage here are some hints that might help others, too.

If you use snapper's timeline feature with the default values for daily/monthly/yearly snapshots, you may notice a serious slowdown of your filesystem. On my SSD I sometimes saw performace drop to 5MB/s and complete stalls. This is due to having way too many snapshots spread across a large time frame.