Rich0's Gentoo Blog

btrfs and snapper with portage on Gentoo

with 2 comments

This is just a quick share-a-recipe post to introduce snapper to anybody who hasn’t heard of it, and explain how to use it.

Snapper is a utility that manages btrfs snapshots.  One of the nice features of btrfs is that snapshots are cheap (virtually instant, and consume space only as changes accumulate), and easy to access.  Snapper allows you to automatically create and manage them based on time, events, manual action, etc.

Once snapper is set up you can display a list of snapshots.  I have 10 hourly snapshots, 10 daily snapshots, and snapshots from before/after each emerge.  I can diff them, browse them, etc.  Btrfs snapshots can be browsed right from the filesystem, so if I nuke /etc/passwd I can always do a cp /.snapshots/1875/snapshot/etc/passwd /etc/passwd to restore one from a few hours before (though I do also have /etc in a git repo).

Snapper is currently available in the sunrise overlay – I won’t spend time on how to set that up/etc.  Also, I’ve had time-based snapshots running for a while now and my memory is hazy as to whether I had to do anything to get those working – it just requires sticking some scripts in /etc/cron.*/ and creating a config file containing your policies.

What I did want to post is a recipe for getting pre/post-emerge snapshots working.  All you need to do is add some lines to /etc/portage/bashrc:

case "${EBUILD_PHASE}" in
        preinst) 
                DESC="${CATEGORY}/${PF}"
                NUMBER=`snapper create -t pre -p -d "${DESC}"`
                ;;
        postinst) 
                snapper create -t post --pre-number $NUMBER -d "${DESC}"
                ;;
esac

One of these days I might clean this up a bit and move it to portage.

About these ads

Written by rich0

November 26, 2013 at 3:52 pm

Posted in foss, gentoo, linux

2 Responses

Subscribe to comments with RSS.

  1. Great hint rich0.
    It was just yesterday, when I was looking if snapper is in the regular portage tree.
    I read about his tool long time ago in some magazines, which is from Suse AFAIK.
    Good that it is also available for us Gentoo users ;-)

    Installing it out of the sunrise overlay is no problem so far, but the bashrc rule seems to be very helpful to me.

    Best, Andy.

    Andy

    November 27, 2013 at 6:46 am

    • Part of me thinks that I also had to tweak the cron job as well, or some other config file. If I get a chance I’ll do a diff of the default config vs what I have in /etc and see what comes up. If I get more time I might even move it into the tree (looks like they have recent releases too).

      rich0

      November 27, 2013 at 8:04 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: