[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.
-
Install snapper (it's in the community repo)
sudo pacman -S snapper -
Generate a snapper config
sudo snapper create-config / -
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"
-
Start and enable cronie in systemd
sudo systemctl start cronie sudo systemctl enable cronie -
Now here's the fun part. I modified a script on github that wraps a shell command in snapper snapshots. Here it is
-
Download it and put it somewhere in your path (/usr/local/bin for example) Make it executable
sudo chmod +x /usr/local/bin/snp -
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 -
I also wrote a script that makes undoing an upgrade or reverting to a previous snapshot by date easily. Here it is
-
Save the script in the same directory as you saved the snp script then make it executable
sudo chmod +x /usr/local/bin/rollback -
Enjoy the security and peace of mind that filesystem snapshots bring :)
About this post
- Posted
- Archived
- Score
- 40 · 100% up
- Kind
- Text
- ID
- 283rog
12 comments
Deleted before we saved it.
Because that's what snapper uses by default
OpenSuse does this (by default?) as well. If you run a software upgrade it takes a snapshot first. Useful!
openSUSE was actually my inspiration for this. Snapper was developed by SUSE and is integrated with zypper
This is my upgrade script. I like to
pacman -Syuwoutside of the snapshot block, and do only thepacman -Suin the snapshot so it’s is as thin as possible. Also, I have a separate/bootpartition (root is on LUKS+LVM), so I synchronize that into a backup directory inside the snapshot. (If I ever have to revert, I’ll justrsyncthat back into/bootafter rolling it back.)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?
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
I use btrfs on all of my drives and it works perfectly fine. This is just anecdotal evidence though.
Be careful if you use btrfs. Btrfs has really ineffective recovery tools and one mistake like an unclean shutdown can mess everything up.
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?
Snapper is actually a frontend for Btrfs snapshots.
Thanks for your sane defaults. 10 of everything is so much.