功能
- 备份群文件根目录以及群文件夹内的文件;
- 按文件大小过滤,并可忽略根目录中的指定后缀;
- 已存在且大小相同的文件不会重复下载;
- 将本地备份恢复至原群或迁移至新群;
- 使用
aiohttp流式下载,不阻塞事件循环,也不会把大文件一次性读入内存; - 每个群的任务串行执行,避免并发命令破坏同一份备份。
本插件仅支持 nonebot-adapter-onebot 的 OneBot V11。实际可用性取决于协议实现端是否实现群文件相关动作;恢复文件及创建文件夹通常要求机器人具有群管理员权限。
安装
使用 NB-CLI(商店推荐方式):
nb plugin install nonebot-plugin-backup
使用 uv:
uv add nonebot-plugin-backup
然后按 NoneBot 的插件加载方式加载 nonebot_plugin_backup。
配置
所有配置均为可选项,插件可以零配置加载。可在 NoneBot 的 .env 或 .env.* 中设置:
| 配置项 | 类型 | 默认值 | 说明 |
|---|---|---|---|
backup_group |
set[str] |
set() |
允许使用插件的群号;空集合允许所有群 |
backup_command |
str |
备份群文件 |
备份命令 |
recovery_command |
str |
恢复群文件 |
恢复命令 |
backup_permission |
1 | 2 | 3 |
2 |
1 仅超级用户;2 群主/群管理员/超级用户;3 所有群成员 |
backup_maxsize |
float |
300 |
单文件上限,单位 MiB |
backup_minsize |
float |
0.01 |
单文件下限,单位 MiB |
backup_temp_files |
bool |
true |
是否备份群文件根目录中的临时文件 |
backup_temp_file_ignore |
set[str] |
{.gif,.png,.jpg,.mp4} |
根目录忽略的文件后缀,不区分大小写 |
backup_request_timeout |
float |
60 |
单次下载总超时,单位秒 |
backup_chunk_size |
int |
65536 |
流式下载块大小,单位字节 |
示例:
BACKUP_GROUP=["123456789"]
BACKUP_PERMISSION=2
BACKUP_MAXSIZE=500
BACKUP_TEMP_FILE_IGNORE=[".gif", ".png", ".jpg", ".mp4"]
使用
在允许的群中发送 备份群文件 即可备份。发送 恢复群文件 会将该群对应的数据上传回群文件。
数据目录由 nonebot-plugin-localstore 管理,不再依赖机器人进程的当前工作目录。迁移到新群时,先找到 localstore 分配给本插件的数据目录,再将旧群号目录复制并改名为新群号。
下载采用临时 .part 文件并在成功后原子替换目标文件。下载失败不会留下看似完整的文件;恢复时同名远端文件会被跳过,不会覆盖。
开发
uv sync --all-groups
uv run ruff format .
uv run ruff check .
uv run pytest
uv build
当前发布规范核查见 docs/nonebot-plugin-publishing-research.md。
许可证
Metadata
Release files for nonebot-plugin-backup 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nonebot_plugin_backup-2.1.0.tar.gz | 133.3 kB | Without provenance | Details for nonebot_plugin_backup-2.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nonebot_plugin_backup-2.1.0-py3-none-any.whl | Python 3 | none | any | Details for nonebot_plugin_backup-2.1.0-py3-none-any.whl |
Total release size: 167.0 kB
Release files / nonebot_plugin_backup-2.1.0.tar.gz
| Download URL | nonebot_plugin_backup-2.1.0.tar.gz |
|---|---|
| Size | 133.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21fdc369cfd630228528a069acda8ae0ef602adb9601696a2ca3eb49e882f74f
|
|
BLAKE2b-256 checksum How to use checksums |
713e31bc0b7e87a7c886947f80c83ea4c4c3cae696c40e38e7ce2b1b75e9d4cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.7
|
Release files / nonebot_plugin_backup-2.1.0-py3-none-any.whl
| Download URL | nonebot_plugin_backup-2.1.0-py3-none-any.whl |
|---|---|
| Size | 33.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
746b48476233d8797905a7884917f2f74b1ef79ff973635487a0ef0ecc61d478
|
|
BLAKE2b-256 checksum How to use checksums |
952f6e229b8a5683c7f19367a08f0ebf093eb35df7e2e1b90f24ce019d65fbf3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.7
|
Security for nonebot-plugin-backup 2.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.