Snapper is a snapshot-manager for Linux. It can create, delete and compare snapshots and undo changes done between snapshots. It supports btrfs and LVM with thin-provisioning. Snapper can also automatically create snapshots(with cleanup strategies of old snapshots).
Install
echo "deb http://download.opensuse.org/repositories/filesystems:/snapper/Debian_8.0/ /" >> /etc/apt/sources.list.d/snapper.list
wget http://download.opensuse.org/repositories/filesystems:snapper/Debian_8.0/Release.key
apt-key add - < Release.key
apt-get update
apt-get install snapper
Create a config
Let’ assume we have a btrfs-subvolume mounted in /home. Then we can create a config for it using the following command:
snapper -c Home create-config /home
Snapper creates a config-file under /etc/snapper/configs/Home:
# subvolume to snapshot
SUBVOLUME="/home"
# filesystem type
FSTYPE="btrfs"
# users and groups allowed to work with config
ALLOW_USERS=""
ALLOW_GROUPS=""
# sync users and groups from ALLOW_USERS and ALLOW_GROUPS to .snapshots
# directory
SYNC_ACL="no"
# start comparing pre- and post-snapshot in background after creating
# post-snapshot
BACKGROUND_COMPARISON="yes"
# run daily number cleanup
NUMBER_CLEANUP="yes"
# limit for number cleanup
NUMBER_MIN_AGE="1800"
NUMBER_LIMIT="50"
NUMBER_LIMIT_IMPORTANT="10"
# create hourly snapshots
TIMELINE_CREATE="yes"
# cleanup hourly snapshots after some time
TIMELINE_CLEANUP="yes"
# limits for timeline cleanup
TIMELINE_MIN_AGE="1800"
TIMELINE_LIMIT_HOURLY="10"
TIMELINE_LIMIT_DAILY="10"
TIMELINE_LIMIT_WEEKLY="0"
TIMELINE_LIMIT_MONTHLY="10"
TIMELINE_LIMIT_YEARLY="10"
# cleanup empty pre-post-pairs
EMPTY_PRE_POST_CLEANUP="yes"
# limits for empty pre-post-pair cleanup
EMPTY_PRE_POST_MIN_AGE="1800"
As we can see, snapper will automatically create snapshots
We can list all configs calling:
root@tardis:/home/dr# snapper list-configs
Konfiguration | Subvolumen
--------------+-----------
root | /mnt/Raid
Home | /home
Creating manual snapshots
snapper -c Home create -d "First cool snapshot"
snapper -c Home list
Typ | # | Vorher # | Datum | Benutzer | Bereinigen | Beschreibung | Benutzerdaten
-------+---+----------+------------------------------+----------+------------+---------------------+--------------
single | 0 | | | root | | current |
single | 1 | | Fre 11 Mär 2016 15:17:01 CET | root | timeline | timeline |
single | 2 | | Fre 11 Mär 2016 15:22:33 CET | root | | First cool snapshot |
Delete Snapshots
Automatically created Snapshots will also be deleted automatically. If you want to manually delete some snapshots it’s easy like creating them:
snapper -c Home delete 2
snapper -c Home list
Typ | # | Vorher # | Datum | Benutzer | Bereinigen | Beschreibung | Benutzerdaten
-------+---+----------+------------------------------+----------+------------+--------------+--------------
single | 0 | | | root | | current |
single | 1 | | Fre 11 Mär 2016 15:17:01 CET | root | timeline | timeline |
Mounting Snapshots
If you want to mount any snapshot you can just call:
snapper -c Home mount 1
ls -l /home/.snapshots/1/snapshot/
insgesamt 4
-rw-r--r-- 1 dr dr 189 Jun 9 2007 tardis.txt
drwx------ 1 rose rose 2392 Sep 18 2013 rose
drwx------ 1 dr dr 8966 Mär 11 15:15 dr
drwx------ 1 dr dr 2916 Jul 10 2009 dr_old
snapper -c Home umount 1
Final Words
Snapper is great. It’s very easy to use. If you create a config it will automatically create hourly snapshots and rotate them. I mostly use snapper in combination with BTRFS and LXC-Container. But I also have other configurations using thin provisioned LVM’s for example. I think it’s a great addition to backups since it’s very lightweight.