Simple Automated btrfs Snapshots with btrfs-snap

| Comments

I was running btrfs for almost a month before I got around to setting up some automated snapshotting. I was expecting to have to write some scripts of my own, but I luckily I found btrfs-snap. All you have to do is pass btrfs-snap the path of the volume to snapshot, a tag for the snapshot (daily, weekly, etc), and the number of snaphots to keep. It stores the snapshots in a .snapshot directory at the root of the volume and names the snapshots using the tag and a time stamp.

I have mine set up to keep 4 weekly snapshots, 7 daily snapshots, and 24 hourly snapshots. I also tried keeping a dozen five-minute snapshots (fivers). Things got gummed up when I tried that and I had dozens of snapshots processes sitting around idling. I could probably get around that issue by making sure only one snapshot job is running at any given time.

Here’s my cron scripts:

/etc/cron.hourly/btrfs-snap
1
2
3
4
5
#! /bin/bash

/usr/local/bin/btrfs-snap / hourly 24
/usr/local/bin/btrfs-snap /home hourly 24
/usr/local/bin/btrfs-snap /home/wonko/wip hourly 24

/etc/cron.daily/btrfs-snap
1
2
3
4
5
#! /bin/bash

/usr/local/bin/btrfs-snap / daily 7
/usr/local/bin/btrfs-snap /home daily 7
/usr/local/bin/btrfs-snap /home/wonko/wip daily 7
/etc/cron.weekly/btrfs-snap
1
2
3
4
5
#! /bin/bash

/usr/local/bin/btrfs-snap / weekly 4
/usr/local/bin/btrfs-snap /home weekly 4
/usr/local/bin/btrfs-snap /home/wonko/wip weekly 4

And here is a set of snapshots:

Some snapshots
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
wonko@zaphod:~$ ls /home/.snapshot
daily_2010-09-04_07:43:13   hourly_2010-09-12_00:17:01
daily_2010-09-05_07:28:22   hourly_2010-09-12_01:17:02
daily_2010-09-06_08:05:00   hourly_2010-09-12_02:17:01
daily_2010-09-09_06:44:39   hourly_2010-09-12_03:17:02
daily_2010-09-10_08:00:54   hourly_2010-09-12_04:17:01
daily_2010-09-11_07:59:08   hourly_2010-09-12_05:17:03
daily_2010-09-12_07:51:40   hourly_2010-09-12_06:17:01
hourly_2010-09-11_13:17:01  hourly_2010-09-12_07:17:01
hourly_2010-09-11_14:17:02  hourly_2010-09-12_08:17:02
hourly_2010-09-11_15:17:02  hourly_2010-09-12_09:17:02
hourly_2010-09-11_17:17:02  hourly_2010-09-12_10:17:01
hourly_2010-09-11_18:17:01  hourly_2010-09-12_11:17:01
hourly_2010-09-11_19:17:01  hourly_2010-09-12_12:17:02
hourly_2010-09-11_20:17:01  hourly_2010-09-12_13:17:01
hourly_2010-09-11_21:17:02  weekly_2010-09-02_07:51:13
hourly_2010-09-11_22:17:01  weekly_2010-09-09_16:00:25
hourly_2010-09-11_23:17:02  weekly_2010-09-12_07:52:39

Everything has been running fine for about a month. I haven’t filled up my disk with junk snapshots yet. One of the nice things about these writeable snapshots is that I can always prune big files that I don’t need right out of them.

Comments