Snapper is a tool created by openSUSE's Arvin Schnell that helps with managing snapshots of Btrfs subvolumes and thin-provisioned LVM volumes. It can create and compare snapshots, revert between snapshots, and supports automatic snapshots timelines.
- 1 Installation
- 2 Create a new configuration
- 3 Take snapshots
- 4 List snapshots
- 5 List configurations
- 6 Delete a snapshot
- 7 Access for non-root users
- 8 Tips and tricks
- 8.1 Wrapping pacman transactions in snapshots
- 8.2 Incremental backup to external drive
- 8.3 Suggested filesystem layout
- 8.4 Deleting files from snapshots
- 8.5 Preventing slowdowns
- 8.6 Preserving log files
- 8.7 Cleanup based on disk usage
- 9 Troubleshooting
- 10 See also
Install the package. The development version AUR is also available.
Additionally, a GUI is available withAUR.
Create a new configuration
Before creating a snapper configuration for a btrfs subvolume, the subvolume must already exist. If it does not, you should create it before generating a snapper configuration.
To create a new snapper configuration named
config for the btrfs subvolume at
# snapper -c config create-config /path/to/subvolume
- create a configuration file at
/etc/snapper/configs/configbased on the default template from
- create a subvolume at
/path/to/subvolume/.snapshotswhere future snapshots of for this configuration will be stored. A snapshot's path is
#is the snapshot number.
For example, to create a configuration file for the subvolume mounted at
# snapper -c root create-config /
At this point, the configuration is active. If your cron daemon is running, snapper will take #Automatic timeline snapshots. If you do not use a cron daemon, you will need to use the systemd service and timer. See #Enable/disable.
See man page for
Automatic timeline snapshots
A snapshot timeline can be created with a configurable number of snapshots kept per hour/day/month/year. When the timeline is enabled, by default a snapshot gets created once an hour. Once a day the snapshots get cleaned up by the timeline cleanup algorithm.
If you have a cron daemon, this feature should start automatically. To disable it, edit the configuration file corresponding with the subvolume you do not want to have this feature and set:
If you do not have a cron daemon, you can use the provided systemd units. Start and enable
snapper-timeline.timer to start the automatic snapshot timeline. Additionally, start and enable
snapper-cleanup.timer to periodically cleanup older snapshots.
Set snapshot limits
The default settings will keep 10 hourly, 10 daily, 10 monthly and 10 yearly snapshots. You may want to change this in the configuration, especially on busy subvolumes like
/. See #Preventing slowdowns.
Here is an example section of a configuration named
config with only 5 hourly snapshots, 7 daily ones, no monthly and no yearly ones:
TIMELINE_MIN_AGE="1800" TIMELINE_LIMIT_HOURLY="5" TIMELINE_LIMIT_DAILY="7" TIMELINE_LIMIT_WEEKLY="0" TIMELINE_LIMIT_MONTHLY="0" TIMELINE_LIMIT_YEARLY="0"
Change snapshot and cleanup frequencies
If you are using the provided systemd timers, you can edit them to change the snapshot and cleanup frequency.
For example, when editing the
snapper-timeline.timer, add the following to make the frequency every five minutes, instead of hourly:
[Timer] OnCalendar= OnCalendar=*:0/5
snapper-cleanup.timer, you need to change
OnUnitActiveSec. To make cleanups occur every hour instead of every day, add:
By default snapper takes snapshots that are of the simple type, having no special relationship to other snapshots.
To take a snapshot of a subvolume manually, do:
# snapper -c config create --description desc
The above command does not use any cleanup algorithm, so the snapshot is stored permanently or until deleted.
To set a cleanup algorithm, use the
-c flag after
create and choose either
number sets snapper to periodically remove snapshots that have exceeded a set number in the configuration file. For example, to create a snaphot that uses the
number algorithm for cleanup do:
# snapper -c config create -c number
In addition to simple snapshots, you can also create pre/post snapshots where pre snapshots always have a corresponding post snapshot. The purpose of these pairs is to create a snapshot before and after a system modification.
To create a pre/post snapshot pair, first create a pre snapshot:
# snapper -c config create -t pre -p
Note the number of the snapshot printed, as it is required for the post snapshot.
Then perform a system modification (*e.g.*, install a new program, upgrade, etc.).
Now create the post snapshot:
# snapper -c config create -t post --pre-number N
N is the corresponding pre snapshot number.
An alternative method is to use the
--command flag for
create, which wraps a command with pre/post snapshots:
# snapper -c config create --command cmd
cmd is the command you wish to wrap with pre/post snapshots.
Snapshots on boot
To have snapper take a snapshot of the
root configuration, enable
To list snapshots taken for a given configuration config do:
# snapper -c config list
To list all configurations you have created do:
# snapper list-configs
Delete a snapshot
To delete a snapshot number
# snapper -c config delete N
Multiple snapshots can be deleted at one time. For example, to delete snapshots 65 and 70 of the root configuration do:
# snapper -c root delete 65 70
Access for non-root users
Each config is created with the root user, and by default, only root can see and access it.
To be able to list the snapshots for a given config for a specific user, simply change the value of
ALLOW_USERS in your
/etc/snapper/configs/config file. You should now be able to run
snapper -c config list as a normal user.
Eventually, you want to be able to browse the
.snapshots directory with a user, but the owner of this directory must stay root. Therefore, you should change the group owner by a group containing the user you are interested in, such as
users for example:
# chmod a+rx .snapshots # chown :users .snapshots
Tips and tricks
Wrapping pacman transactions in snapshots
There are a couple of packages used for automatically creating snapshots upon a pacman transaction:
- snap-pac — "Makes pacman automatically use snapper to create #Pre/post snapshots like openSUSE's YaST". Uses Pacman#Hooks.
- pacupg — "Script that wraps package and AUR upgrades in btrfs snapshots and provides an easy way to roll them back."
Backup non-btrfs boot partition on pacman transactions
/boot partition is on a non btrfs filesystem (e.g. an ESP) you are not able to do snapper backups with it. You can copy the boot partition automatically on a kernel update to your btrfs root with a hook. This also plays nice together with .
[Trigger] Operation = Upgrade Operation = Install Operation = Remove Type = Package Target = linux [Action] Depends = rsync Description = Backing up /boot... When = PreTransaction Exec = /usr/bin/rsync -avzq --delete /boot /.bootbackup
Incremental backup to external drive
The following packages use
btrfs send and
btrfs receive to send backups incrementally to an external drive. Refer to their documenation to see differences in implementation, features, and requirements.
- snap-sync — "Use snapper snapshots to backup to external drive."
- snapsync — "A synchronization tool for snapper"
- buttersink — "Buttersink is like rsync for btrfs snapshots."
Suggested filesystem layout
Here is a suggested file system layout for easily restoring your
/ to a previous snapshot:
subvolid=5 | ├── @ | | | ├── /usr | | | ├── /bin | | | ├── /.snapshots | | | ├── ... | ├── @snapshots | └── @...
/.snapshots is a mountpoint for
@... are subvolumes that you want to keep separate from the subvolume you will be mounting as
@). When taking a snapshot of
/, these other subvolumes are not included. However, you can still snapshot these other subvolumes separately by creating other snapper configurations for them. Additionally, if you were to restore your system to a previous snapshots of
/, these other subvolumes will remain unaffected.
For example if you want to be able restore
/ to a previous snapshot but keep your
/home intact, you should create a subvolume that will be mounted at
/home. See Btrfs#Mounting subvolumes.
This layout allows the snapper utility to take regular snapshots of
/, while at the same time making it easy to restore
/ from an Arch Live CD if it becomes unbootable.
In this sceneario, after the initial setup, snapper needs no changes, and will work as expected.
Configuration of snapper and mount point
/.snapshots is not mounted and does not exist as folder.
# umount /.snapshots # rm -r /.snapshots
Then #Create a new configuration for
For example, for a file system located on
# mount -o subvol=@snapshots /dev/sda1 /.snapshots
To make this mount permanent, add an entry to your fstab.
Or if you have an existing fstab entry remount the snapshot subvolume:
# mount -a
Give the folder
This will make all snapshots that snapper creates be stored outside of the
@ subvolume, so that
@ can easily be replaced anytime without losing the snapper snapshots.
/ to a previous snapshot of
If you ever want to restore
/ using one of snapper's snapshots, first boot into a live Arch Linux USB/CD.
Mount the toplevel subvolume (subvolid=5). That is, omit any
subvolid mount flags.
Find the snapshot you want to recover in
Browse through the
<description> tags and the
<date> tags, and when you find the snapshot you wish to restore, remember the
@ to another location (e.g.
/@.broken) to save a copy of the current system. Alternatively, simply delete
btrfs subvolume delete.
Create a read-write snapshot of the read-only snapshot snapper took:
# btrfs subvol snapshot /mnt/@snapshots/#/snapshot /mnt/@
# is the number of the snapper snapshot you wish to restore. Your
/ has now been restore to the previous snapshot. Now just simply reboot.
Deleting files from snapshots
If you want to delete a specific file or folder from past snapshots without deleting the snapshots themselves, snapperS is a script that adds this functionality to Snapper. This script can also be used to manipulate past snapshots in a number of other ways that Snapper does not currently support.
If you want to remove a file without using an extra script, you just need to make your snapshot subvolume read-write, which you can do with:
# btrfs property set /path/to/.snapshots/<snapshot_num>/snapshot ro false
verify that ro=false:
# btrfs property get /path/to/.snapshots/<snapshot_num>/snapshot ro=false
You can now modify files in /path/to/.snapshots/<snapshot_num>/snapshot like normal. You can use a shell loop to work on your snapshots in bulk.
Keeping many of snapshots for a large timeframe on a busy filesystem like
/, where many system updates happen over time, can cause serious slowdowns. You can prevent it by:
- Creating subvolumes for things that are not worth being snapshotted, like
- Editing the default settings for hourly/daily/monthly/yearly snapshots when using #Automatic timeline snapshots.
updatedb will also index the
.snapshots directory created by snapper, which can cause serious slowdown and excessive memory usage if you have many snapshots. You can prevent
updatedb from indexing over it by editing:
PRUNENAMES = ".snapshots"
Preserving log files
It's recommended to create a subvolume for
/var/log so that snapshots of
/ exclude it. That way if a snapshot of
/ is restored your log files will not also be reverted to the previous state. This make it easier to troubleshoot.
Cleanup based on disk usage
Snapper writes all activity to
/var/log/snapper.log - check this file first if you think something goes wrong.
If you have issues with hourly/daily/weekly snapshots, the most common cause for this so far has been that the cronie service (or whatever cron daemon you are using) was not running.
If you get an 'IO Error' when trying to create a snapshot please make sure that the .snapshots directory associated to the subvolume you are trying to snapshot is a subvolume by itself.
Another possible cause is that .snapshots directory does not have root as an owner (You will find
Btrfs.cc(openInfosDir):219 - .snapshots must have owner root in the