| Crates.io | simple-snap |
| lib.rs | simple-snap |
| version | 0.1.1 |
| created_at | 2025-07-06 08:05:10.984771+00 |
| updated_at | 2025-07-07 20:06:40.074282+00 |
| description | Minimalist BTRFS periodic snapshot tool |
| homepage | |
| repository | https://github.com/oxalica/simple-snap |
| max_upload_size | |
| id | 1739968 |
| size | 29,701 |
Minimalist BTRFS periodic snapshot tool. Snapshot, prune, and nothing else.
This tool is for ones who know how BTRFS subvolumes and snapshots work. The main purpose of this periodic snapshot tool is to:
rm, git reset --hard.git commit breaks the repository
during a power loss, game save bricks after a crash.This tool does NOT:
$ simple-snap --target-dir /.snapshots --source /home/alice --prefix home-alice@
created snapshot "/.snapshots/home-alice@2025-07-06T00:29:43.190772445-04:00" for "/home/alice"
Note that subvolume deletion requires either root permission, or mount option
user_subvol_rm_allowed is used and the effective user owns the subvolume.
The prune policy mimic options of restic forget --keep-*.
See their documentation
or run simple-snap prune --help for detail explanations.
# simple-snap prune \
--target-dir /.snapshots \
--prefix home-alice@ \
--keep-within 6h \
--keep-daily 7 \
--keep-hourly 48 \
--keep-last 2
home-alice@2025-07-06T00:30:06.123456789-04:00 last-within,last-n,hourly,daily
home-alice@2025-07-06T00:15:06.123456789-04:00 last-within,last-n
home-alice@2025-07-06T00:00:03.123456789-04:00 last-within
home-alice@2025-07-05T23:45:16.123456789-04:00 last-within,hourly,daily
[..]
home-alice@2025-06-29T06:00:01.123456789-04:00 !!delete!!
---
would keep 69 of 74 snapshots, and delete 5 snapshots.
deleted 5 snapshots (no commit).
Note that we do not commit subvolume deletion. I personally think it unnecessary
and may hurt disk performance when running prune periodically.
You may run btrfs filesystem sync /path/to/btrfs yourself if you do want a
BTRFS transaction commit.
You are expected to use cron or systemd timer to run simple-snap periodically.
All timestamps, date time options use local time zone with an (automatic) explicit offset, so it is unambiguous when switching time zones and also easy to understand for human, if you are not in the +00:00 zone.
If you are a UTC-fan, set environment variable TZ=Etc/UTC to force all date time to use UTC.
We also use specified units for calendar arithmetic. This means, for
example, --keep-with-in 1mo will keep snapshots from (month-1)-(day) to
(month)-(day), no matter how many days there are in the last month.
The code is ~500LoC and should be easy to reviewable.
Since prune requires root, please review it by yourself before use, especially the unsafe parts.
We call ioctl directly, thus has no btrfs-progs dependency.
unsafe only comes from 3 BTRFS ioctls, under src/ioctl.rs.
All used ioctls are officially documented.