Skip to content

Feature/删除了 Rclone 配置检测,增加了 sh 脚本清理函数无视风险继续执行的功能,移除Kopia自动连接功能#15

Merged
YewFence merged 8 commits intomainfrom
feature/config-file-route
Feb 1, 2026
Merged

Feature/删除了 Rclone 配置检测,增加了 sh 脚本清理函数无视风险继续执行的功能,移除Kopia自动连接功能#15
YewFence merged 8 commits intomainfrom
feature/config-file-route

Conversation

@YewFence
Copy link
Copy Markdown
Owner

@YewFence YewFence commented Feb 1, 2026

Summary by CodeRabbit

  • New Features

    • Added optional KOPIA_CONFIG_FILE and RCLONE_CONFIG environment variables for file-based multi-user configuration
    • Kopia can run independently; rclone is now optional
  • Documentation

    • README updated with Kopia-first quick start, optional rclone notes, and log ordering/version context
  • Bug Fixes / UX

    • Improved dependency and status checks, clearer error guidance, safer cleanup and more accurate dry-run command display

✏️ Tip: You can customize this high-level summary in your review settings.

YewFence and others added 7 commits January 25, 2026 21:35
新增环境变量:
- KOPIA_CONFIG_FILE: 指定 kopia 配置文件路径
- RCLONE_CONFIG: 指定 rclone 配置文件路径(rclone 原生支持)

用于以其他用户身份(如 root)运行脚本时,无需复制配置文件
新增环境变量:
- KOPIA_CONFIG_FILE: 指定 kopia 配置文件路径
- RCLONE_CONFIG: 指定 rclone 配置文件路径

通过 buildKopiaArgs() 和 buildEnv() 方法统一处理命令参数和环境变量
- Shell: 重构命令执行方式,使用 run_kopia() 函数替代字符串拼接,正确处理含空格的路径
- Shell/Go: 添加配置文件存在性检查,在依赖检查阶段提前发现问题
- Go: 优化 buildEnv(),在初始化时缓存环境变量避免重复复制

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- 移除 Kopia 密码配置项和自动仓库连接逻辑
- 移除 rclone 依赖检查,仅保留 kopia 检查
- 要求用户手动执行 'kopia repository connect' 连接仓库
- 添加 .claude/ 目录到 .gitignore
- 简化依赖检查流程,提高配置明确性
在 cleanup() 函数开头添加 `set +e` 命令,防止清理过程中某个命令失败导致后续清理逻辑中断,确保所有服务恢复操作都能被执行。
- 将 rclone 从必需依赖调整为可选依赖,更准确反映工具使用场景
- 修正 Gist 日志排序描述,由于日期递增,最新日志实际在最下方
- 更新安装说明,标注 rclone 为按需安装
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @YewFence, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求主要优化了备份工具的依赖管理和配置灵活性。它取消了对 Rclone 配置的强制性检查和 Kopia 仓库的自动连接机制,转而提供手动连接的指导,并引入了自定义 Kopia 和 Rclone 配置文件路径的功能,以适应更复杂的运行环境。此外,改进了 Shell 脚本的清理逻辑,确保在异常情况下也能更可靠地恢复服务。

Highlights

  • 依赖管理优化: 移除了对 Rclone 配置的强制检测,并将其降级为可选依赖。同时,取消了 Kopia 仓库的自动连接功能,现在要求用户手动连接仓库以提高透明度和控制力。
  • 配置文件路径自定义: 引入了对 Kopia 和 Rclone 自定义配置文件路径的支持。通过新增的 KOPIA_CONFIG_FILERCLONE_CONFIG 环境变量,用户可以在脚本以不同用户身份运行时指定特定的配置文件,增强了灵活性。
  • 脚本健壮性提升: 增强了 Shell 脚本的清理函数 (cleanup),使其在遇到错误时也能继续执行后续清理逻辑(通过 set +e),从而提高了脚本在异常情况下的健壮性和可靠性。
  • 代码结构优化: Go 语言部分的代码进行了重构,移除了 Kopia 密码字段,并引入了 buildKopiaArgsbuildEnv 等辅助函数,以更好地管理 Kopia 命令的参数和环境变量,支持自定义配置文件。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 1, 2026

📝 Walkthrough

Walkthrough

Password-based Kopia auth was replaced with file-based configuration via KOPIA_CONFIG_FILE and optional RCLONE_CONFIG. Go and shell code now pass config paths and cached env to Kopia invocations, rclone is optional, and automatic repository connect logic was removed; dependency checks and commands were adjusted accordingly.

Changes

Cohort / File(s) Summary
Config & Docs
/.env.example, README.md, /.gitignore
Added examples for KOPIA_CONFIG_FILE and RCLONE_CONFIG; documentation updated to mark rclone optional and include Kopia install notes; .claude/ added to gitignore.
Go: core backup & config
go/backup.go, go/config.go, go/orchestrator.go
Removed password field; added configFile, rcloneConfig, cachedEnv; updated NewKopiaBackup signature; added buildKopiaArgs/buildEnv; CheckDependencies/CheckRepository/CreateSnapshot now use optional config file and env; removed auto-connect logic.
Shell: config & dependencies
src/03-config.sh, src/07-dependencies.sh
Introduced KOPIA_CONFIG_FILE and RCLONE_CONFIG; export RCLONE_CONFIG when set; added run_kopia() and get_kopia_cmd_display() helpers; dependency checks now validate optional config files and no longer require rclone.
Shell: control flow / invocation
src/08-services.sh, src/09-main.sh
Added set +e in cleanup to ensure cleanup runs; replaced direct kopia calls with run_kopia and updated dry-run display via get_kopia_cmd_display.

Sequence Diagram(s)

sequenceDiagram
    participant Env as Environment<br/>(KOPIA_CONFIG_FILE, RCLONE_CONFIG)
    participant Loader as Config Loader<br/>(LoadConfig)
    participant Orchestrator as Orchestrator<br/>(NewOrchestrator)
    participant Backup as KopiaBackup<br/>(buildKopiaArgs / buildEnv)
    participant CLI as Kopia CLI<br/>(kopia)

    Env->>Loader: read KOPIA_CONFIG_FILE,RCLONE_CONFIG
    Loader->>Orchestrator: provide Config
    Orchestrator->>Backup: NewKopiaBackup(expectedRemote, configFile, rcloneConfig, dryRun)
    Backup->>Backup: cache configFile & rcloneConfig<br/>prepare cachedEnv
    Backup->>CLI: run kopia ... --config-file=<path> (with cached env)
    CLI-->>Backup: repository status / snapshot result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 A hop for config, a nibble of file,
No whispered passwords, the paths make me smile.
Rclone may wander, optional and spry,
Kopia reads calmly, beneath moonlit sky,
Backups hum softly — I twitch my ear, bye-bye.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title comprehensively covers the three main changes: removing Rclone config detection, adding error-resilient cleanup in shell scripts, and removing Kopia auto-connection.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/config-file-route

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

这个 Pull Request 的目标很明确,主要是解耦对 Rclone 的强依赖,移除 Kopia 的自动连接功能以简化逻辑,并增加了对自定义配置文件的支持,同时增强了 Shell 脚本的清理函数健壮性。这些都是非常有价值的改进。

代码的修改在 Go 和 Shell 两个版本中都得到了体现,保持了一致性。

我在审查中发现了一些可以改进的地方,主要集中在 Shell 脚本的实现细节上,有一个关键的错误处理逻辑问题和一个命令参数的遗漏,可能会导致脚本行为不符合预期。具体细节请看我的评论。

Comment thread src/08-services.sh Outdated
Comment thread src/07-dependencies.sh Outdated
Comment thread go/backup.go
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/08-services.sh (1)

214-221: ⚠️ Potential issue | 🟠 Major

Fix exit-code capture order in cleanup.

set +e resets $? to 0, so exit_code is always 0 and the recovery path never runs. Capture $? before disabling errexit.

🛠️ Proposed fix
 cleanup() {
-    set +e  # 禁用错误退出,确保清理逻辑完整执行
-    local exit_code=$?
+    local exit_code=$?
+    set +e  # 禁用错误退出,确保清理逻辑完整执行
     if [ "$exit_code" -ne 0 ]; then
         log "!!! 脚本异常退出,尝试恢复所有服务..."
🤖 Fix all issues with AI agents
In `@go/backup.go`:
- Around line 37-56: The CheckDependencies method currently only verifies that
the rclone config file (k.rcloneConfig) exists but does not verify the rclone
binary; update CheckDependencies to call exec.LookPath("rclone") when
k.rcloneConfig != "" and return a descriptive fmt.Errorf if LookPath fails; also
make the os.Stat checks for k.configFile and k.rcloneConfig treat any non-nil
error as a failure (not only os.IsNotExist) and include the underlying error in
the returned fmt.Errorf so permission/I/O problems are surfaced; keep the
existing kopia exec.LookPath check and final slog.Info call.
- Around line 75-83: The error message returned when kopia repository status
fails should include the config path and rclone config so users can reconnect
with the same settings; update the error returned in the block that calls
k.buildKopiaArgs("repository", "status", "--json") / exec.Command("kopia", ...)
(and uses k.buildEnv()) to include k.configFile and k.rcloneConfig in the manual
connect hint, e.g. append the config file path and rcloneConfig value to the
suggested 'kopia repository connect' command and/or the explanatory text so
users can recreate the original commandline with the correct config context.

Comment thread go/backup.go
Comment thread go/backup.go
**详细说明:**
- 增强配置文件验证,捕获所有访问错误而非仅检查不存在
- 添加 rclone 命令依赖检查
- 优化仓库未连接时的错误提示,根据配置动态生成连接命令
- 修复清理函数中退出码捕获时机问题
- 调整代码格式,统一注释对齐风格
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/07-dependencies.sh`:
- Around line 40-50: When RCLONE_CONFIG is specified, also verify the rclone
binary is available to mirror the Go check (exec.LookPath("rclone")); inside
src/07-dependencies.sh after the existing RCLONE_CONFIG file check, run a shell
check (e.g., command -v rclone or which rclone) and if it is missing emit an
error echo, append a clear message to error_msg (e.g., "rclone 二进制不存在; ") and
set has_error=true so the script fails early just like go/backup.go does when
rclone is required but not installed.

Comment thread src/07-dependencies.sh
@YewFence YewFence merged commit 720bbb7 into main Feb 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant