2 个版本
0.6.10 | 2022年6月29日 |
---|---|
0.6.9 | 2022年6月29日 |
#4 in #vcs
38KB
776 代码行
BTM
区块链时间机器。
BTM 是一种不需要停机时间的增量数据备份机制。
你为什么需要这个?
btm 将为你提供以下能力或优势
- 回滚到指定区块高度的某个状态
- 运行中的热备份,无需停机时间
- 基于操作系统级基础设施,稳定可靠
- 非常小的资源使用,几乎不影响性能
- ...
库用法
use btm::{BtmCfg, SnapMode, SnapAlgo};
let cfg = BtmCfg {
enable: true,
itv: 10,
cap: 100,
mode: SnapMode::Zfs,
algo: SnapAlgo::Fade,
volume: "zroot/data".to_owned(),
};
// Generate snapshots in some threads.
cfg.snapshot(0).unwrap();
cfg.snapshot(1).unwrap();
cfg.snapshot(11).unwrap();
/// Print all existing snapshots.
cfg.list_snapshots();
/// Rollback to the state of the last snapshot.
cfg.rollback(None, false).unwrap();
/// Rollback to the state of a custom snapshot.
cfg.rollback(Some(11), true).unwrap();
二进制用法
btm ...
的用法
btm
USAGE:
btm [OPTIONS] [SUBCOMMAND]
OPTIONS:
-C, --snapshot-clean
clean up all existing snapshots
-h, --help
Print help information
-l, --snapshot-list
list all available snapshots in the form of block height
-p, --snapshot-volume [<VolumePath>...]
a data volume containing your blockchain data
-r, --snapshot-rollback-to [<Height>...]
rollback to a custom height, will try the closest smaller height if the target does not
exist
-R, --snapshot-rollback-to-exact [<Height>...]
rollback to a custom height exactly, an error will be reported if the target does not
exist
-x, --snapshot-rollback
rollback to the last available snapshot
btm daemon ...
的用法
btm-daemon
USAGE:
btm daemon [OPTIONS]
OPTIONS:
-a, --snapshot-algo [<Algo>...]
fair/fade, default to `fair`
-c, --snapshot-cap [<Capacity>...]
the maximum number of snapshots that will be stored, default to 100
-h, --help
Print help information
-i, --snapshot-itv [<Iterval>...]
interval between adjacent snapshots, default to 10 blocks
-m, --snapshot-mode [<Mode>...]
zfs/btrfs/external, will try a guess if missing
-p, --snapshot-volume [<VolumePath>...]
a data volume containing your blockchain data
作为 'systemd 服务' 安装
步骤
make
mv btm_package.tar.gz /tmp/
cd /tmp/
tar -xpf btm_package.tar.gz
cd btm_package
su # swith your user account to 'root'
./install.sh \
--snapshot-itv=4 \
--snapshot-cap=100 \
--snapshot-mode=zfs \
--snapshot-algo=fade \
--snapshot-volume=zfs/data
systemctl status btm-daemon.service
的输出
● btm-daemon.service - "btm daemon"
Loaded: loaded (/lib/systemd/system/btm-daemon.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-10-12 21:24:16 CST; 2min 27s ago
Main PID: 334 (btm)
Tasks: 1 (limit: 37805)
CPU: 1ms
CGroup: /system.slice/btm-daemon.service
└─334 /usr/local/bin/btm daemon -p=/data -i=4 -c=100 -m=btrfs -a=fade
tools/install.sh 的用法
# tools/install.sh -h
Usage
install.sh
--snapshot-itv=<ITV>
--snapshot-cap=<CAP>
--snapshot-mode=<MODE>
--snapshot-algo=<ALGO>
--snapshot-volume=<VOLUME>
Example
install.sh \
--snapshot-itv=4 \
--snapshot-cap=100 \
--snapshot-mode=zfs \
--snapshot-algo=fair \
--snapshot-volume=zfs/blockchain
Example, short style
install.sh -i=4 -c=100 -m=zfs -a=fair -p=zfs/blockchain
install.sh -i=4 -c=100 -m=btrfs -a=fair -p=/data/blockchain
依赖关系
~5.5MB
~115K SLoC