pmbs 0.1.0

(每分钟) 创建 btrfs 快照, 并自动清理. (Make btrfs snapshot (every minute), and auto clean)
Documentation
# 胖喵必快

<https://github.com/fm-elpac/pmbs>

![CI](https://github.com/fm-elpac/pmbs/actions/workflows/ci.yml/badge.svg)

(每分钟) 创建 btrfs 快照, 并自动清理.

Make btrfs snapshot (every minute), and auto clean.

正式名称: 紫腹巨蚊 (Toxorhynchites gravelyi) 系列 澳大利亚海神草 (Posidonia
australis) 软件

**免责声明: 这是开源软件, 没有任何担保, 用户应该承担使用本软件造成的一切后果.**
如果不能接受, 请勿使用本软件 !

---

镜像 (mirror):

- <https://bitbucket.org/fm-elpac/pmbs/>
- <https://codeberg.org/fm-elpac/pmbs>
- <https://notabug.org/fm-elpac/pmbs>
- <https://framagit.org/fm-elpac/pmbs>
- <https://git.disroot.org/fm-elpac/pmbs>
- <https://git.pub.solar/fm-elpac/pmbs>
- <https://gitlink.org.cn/fm-elpac/pmbs>

胖喵必快使用 `root` 权限创建 **只读** btrfs 快照, 所以普通用户 (无 root)
无权限删除快照. 因此可以防止误删文件 (可以从快照找回).

pmbs run as `root` to create **readonly** btrfs snapshot, so normal user (no
root) can not delete snapshot. So can prevent delete files by mistake (can
recovery from snapshot).

## 安装 (install)

- ArchLinux (AUR): <https://aur.archlinux.org/packages/pmbs>

  或者从 [release]https://github.com/fm-elpac/pmbs/releases 下载安装包:

  Or download pre-compiled package from
  [release]https://github.com/fm-elpac/pmbs/releases:

  ```sh
  sudo pacman -U pmbs-bin-0.1.0-1-x86_64.pkg.tar.zst
  ```

- Fedora CoreOS (RPM):

  [release]https://github.com/fm-elpac/pmbs/releases 下载安装包:

  Download pre-compiled package from
  [release]https://github.com/fm-elpac/pmbs/releases:

  ```sh
  sudo rpm-ostree install pmbs-0.1.0-1.fc43.x86_64.rpm
  ```

  然后重启系统.

  And reboot.

<!--
  ---

  启用 SELinux (可选):

  Use SELinux (optional):

  ```sh
  sudo rpm-ostree install pmbs-selinux-0.1.0a5-1.fc43.noarch.rpm
  ```

  TODO
-->

### 安装之后 (after install)

建议将 pmbs 用于保护 **用户数据**, 不建议用于创建 **系统快照**.

Recommend to use pmbs for **user data**, not recommend for create **system
snapshot**.

原因: (1) 系统 (软件) 数据通常是允许丢失的 (比如 `/usr`),
可以重新安装操作系统/软件, 很容易恢复. (2) 系统文件的修改通常不频繁,
不需要分钟级快照 (小时级甚至天级快照已经足够). (3) 对系统创建快照更加复杂,
且可能明显影响系统性能.

---

- (1) 编写配置文件, 比如:

  Edit config file, for example:

  ```sh
  cd /etc/pmbs
  sudo cp home.toml.zh.example home.toml  # or home.toml.en.example
  env EDITOR=nano sudo -e home.toml
  ```

  原则上, 保留规则应该按顺序编写, 上一条规则的间隔时间 (`time`)
  应该比下一条更短, 比如 `1m` (分钟), `5m`, `1h` (小时), `1d` (天). 同时保留个数
  (`n`) 应该大于 0.

  Keep rules should be written in order: `time` of one rule should be shorter
  than the next rule, for example: `1m` (minute), `5m`, `1h` (hour), `1d` (day).
  Number to keep (`n`) should be larger than 0.

- (2) **注意: 请关闭 btrfs `quota` !!** 当 quota 和大量 snapshot 同时使用,
  系统会非常慢 (经常卡死). 检查 quota 是否启用, 比如:

  **Please disable btrfs `quota` !!** When quota is used with a lot snapshots,
  the system will be very slow. Check if quota is enabled, for example:

  ```sh
  > sudo btrfs qgroup show /home
  ERROR: can't list qgroups: quotas not enabled
  ```

  如果启用了, 禁用 quota, 比如:

  If quota is enabled, disable it, for example:

  ```sh
  sudo btrfs quota disable /home
  ```

  参考资料 (reference):

  - <https://www.suse.com/support/kb/doc/?id=000020696>
  - <https://forums.gentoo.org/viewtopic-t-1164227-start-0.html>

- (3) SELinux (Fedora CoreOS) (可选, optional):

  TODO

- (4) 启用 systemd 服务 (定期快照/清理):

  Enable systemd timer (snapshot/clean):

  ```sh
  sudo systemctl enable --now pmbs-snapshot.timer
  sudo systemctl enable --now pmbs-clean.timer
  ```

---

- 列出指定 subvol 的快照, 比如:

  List snapshots of a subvol, for example:

  ```sh
  pmbs ls /home
  ```

- 可以直接使用 `btrfs` 命令删除快照:

  You can delete a snapshot with `btrfs` command:

  <https://wiki.archlinux.org/title/Btrfs#Deleting_a_subvolume>

## 常见问题 (FAQ)

TODO

## 例行更新维护策略 (Release new version policy)

适用于本仓库 (pmbs). 当下列条件任意一条满足时, 本仓库的软件需要发布新的维护版本
(版本号 `x.y.z` 其中 `z` + 1). "更新所有依赖" 并重新编译 (构建):

When any of the following is true, this repo should release a new version
(version number `x.y.z`, `z` + 1). Update all dependencies, and rebuild:

- rustc 发布新版本 (版本号 `x.y.z` 其中 `x``y` 变化)

  rustc release a new version (version number `x.y.z`, `x` or `y` change)

- 各依赖或本仓库发布重要的安全更新 (修复比较严重的安全漏洞)

  The dependencies or this repo release an important security update.

当前重要依赖的版本号:

Current version number of important dependencies:

- rustc 1.93.1 (01f6ddf75 2026-02-11)

  <https://github.com/rust-lang/rust>

## 文档 (doc)

- 主要设计文档: [doc/pmbs.md]./doc/pmbs.md

- SELinux: [doc/selinux.md]./doc/selinux.md

TODO

## LICENSE

`MIT`