Skip to content

[Howto] Integrate filesystem snapshots with pacman

During the summer (when my laptop isn't mission critical) I use the testing repos and file bug reports to try to give back to the Arch community. Just in case, I use snapper to take filesystem snapshots. I would like to share my way of integrating snapper and pacman.

  1. Install snapper (it's in the community repo)

      sudo pacman -S snapper
    
  2. Generate a snapper config

     sudo snapper create-config /
    
  3. Edit the following lines in /etc/snapper/configs/root

    Change TIMELINE_LIMIT_HOURLY to "5"

    Change TIMELINE_LIMIT_DAILY to "7"

    and change TIMELINE_LIMIT_MONTHLY and TIMELINE_LIMIT_YEARLY to "0"

  4. Start and enable cronie in systemd

     sudo systemctl start cronie
    
     sudo systemctl enable cronie
    
  5. Now here's the fun part. I modified a script on github that wraps a shell command in snapper snapshots. Here it is

  6. Download it and put it somewhere in your path (/usr/local/bin for example) Make it executable

     sudo chmod +x /usr/local/bin/snp
    
  7. Make an alias for 'sudo snp pacman -Syu' and put it in the configuration file for your shell (.bashrc, .zshrc, config.fish etc.)

    For example run:

      echo alias pacupg=\'sudo snp pacman -Syu\' >> ~/.bashrc
    
  8. I also wrote a script that makes undoing an upgrade or reverting to a previous snapshot by date easily. Here it is

  9. Save the script in the same directory as you saved the snp script then make it executable

     sudo chmod +x /usr/local/bin/rollback
    
  10. Enjoy the security and peace of mind that filesystem snapshots bring :)

40 points11 comments
Open on Reddit
About this post
Posted
Archived
Score
40 · 100% up
Kind
Text
ID
283rog

Author

33
posts
232
comments
13
media
View profile

12 comments

OpenSuse does this (by default?) as well. If you run a software upgrade it takes a snapshot first. Useful!

3 points

openSUSE was actually my inspiration for this. Snapper was developed by SUSE and is integrated with zypper

2 points

This is my upgrade script. I like to pacman -Syuw outside of the snapshot block, and do only the pacman -Su in the snapshot so it’s is as thin as possible. Also, I have a separate /boot partition (root is on LUKS+LVM), so I synchronize that into a backup directory inside the snapshot. (If I ever have to revert, I’ll just rsync that back into /boot after rolling it back.)

2 points

This is so awesome. I was thinking about it for a long time but I was waiting for btrfs to be mature. Probably I'm going to jump into it on my laptop in near future as it's also not mission critical.

So how stable btrfs is in real life? It should be fine as long as there is battery/upsm right? Is it hard-resetproof?

1 points

Snapper works on ext4. It doesn't require btrfs but as I've never used snapepr on ext4, I can't comment as to how well it works. That being said, btrfs is VERY stable. I've never had any issues with it nor have I heard of anyone whos had issues with it in the last year or so. In fact Facebook uses it on their web-tier servers

1 points

I use btrfs on all of my drives and it works perfectly fine. This is just anecdotal evidence though.

1 points

Be careful if you use btrfs. Btrfs has really ineffective recovery tools and one mistake like an unclean shutdown can mess everything up.

1 points

I've been using Linux for quite a while, but have stuck to the more basic functions except where I need to go further for installations and the like.

Could someone explain exactly how snapshotting a filesystem works in this case, and how it is similar/different to the features that filesystems like BTRFS advertise?

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.