nazar-pc / btrfs同步子卷
这是一个非常简单的实现,从一个位置精确复制一系列子卷到另一个位置,与Just backup btrfs配合良好。
0.3.0
2017-04-27 19:36 UTC
Requires
- php: >=5.6
This package is not auto-updated.
Last update: 2024-09-15 01:12:19 UTC
README
Btrfs同步子卷
这是一个非常简单的实现,从一个位置精确复制一系列子卷到另一个位置,与Just backup btrfs配合良好。
为什么?
我的主要用途是定期对我的系统驱动器(根、家等)进行SSD快照,并将它们复制到外部硬盘,所有这些操作都通过Just backup btrfs原生前进行。
然而,我还想偶尔进行离线备份,本项目正是如此,将所有在线HDD的快照复制到偶尔连接的离线HDD。
要求
- php-cli (版本 5.6+)
安装
整个项目只有一个文件,所以首先的方法是简单地将文件btrfs-sync-subvolumes
复制到某个地方。
或者你可以像这样使用Composer全局安装它
sudo COMPOSER_BIN_DIR=/usr/local/bin composer global require nazar-pc/btrfs-sync-subvolumes
COMPOSER_BIN_DIR=/usr/local/bin
将指示Composer将二进制文件安装到/usr/local/bin
,这样你就可以在安装后立即调用btrfs-sync-subvolumes
。或者你可以跳过它,并将~/.composer/vendor/bin/
添加到你的PATH中。
卸载
如果手动安装,只需删除文件,如果使用Composer安装,请使用以下命令删除
sudo COMPOSER_BIN_DIR=/usr/local/bin composer global remove nazar-pc/btrfs-sync-subvolumes
或者如果你在安装时没有使用COMPOSER_BIN_DIR=/usr/local/bin
,则无需使用它。
使用
Usage:
php btrfs-sync-subvolumes /source/directory /target/directory
It will scan /source/directory for directories and will copy each subvolume to /target/directory.
So, /source/directory/sub1 will be copied as /target/directory/sub1 and so on for each subvolume (binary diffs are used if possible in order to optimize transfer).
As the result it will replicate all subvolumes from /source/directory in /target/directory so that both directories will have the same list of identical subvolumes.
Subvolumes from /target/directory that do not exist in /source/directory will be removed.
NOTE: Important assumptions:
- all directories found in /source/directory are subvolumes (no real check exists)
- each next subvolume (as listed by filesystem) is based on previous, otherwise instead of binary diff the whole subvolume will be copied
有几种运行脚本的方式。
sudo php btrfs-sync-subvolumes
或者将文件标记为可执行,然后
sudo ./btrfs-sync-subvolumes
你还可以使用cron或其他方式调用它:)
它实际上做什么?
- 将
/source/directory
内部的每个目录处理为子卷 - 检查是否在
/target/directory
中存在相同的子卷,如果存在则跳过子卷 - 对于下一个子卷,尝试将其作为二进制差分从上一个子卷发送
- 如果是第一个子卷或使用差分复制失败,则复制整个子卷
- 从
/target/directory
中删除每个在/source/directory
中不存在的子卷(仅当/source/directory
不为空时,以防万一出了点差错)
配置
没有配置或选项,请随意根据您的需求自定义脚本。
许可
MIT,请随意修改并分享!