Skip to content

Update Obsidian Vault backup from copy to in-place git repo; remove old config backups - #249

Merged
bubacoder merged 1 commit into
mainfrom
feature/obsidian-backup
Dec 18, 2025
Merged

Update Obsidian Vault backup from copy to in-place git repo; remove old config backups#249
bubacoder merged 1 commit into
mainfrom
feature/obsidian-backup

Conversation

@bubacoder

@bubacoder bubacoder commented Dec 18, 2025

Copy link
Copy Markdown
Owner

…ld config backups

Summary by CodeRabbit

  • New Features
    • Automatic cleanup of backup files, retaining only the 30 most recent and listing recent backups after a backup completes.
    • Service lifecycle management for Obsidian: explicit stop/start steps around repository operations.
    • Backup/sync workflow now runs pre-commit checks before finalizing commits and operates from the vault path.

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

@coderabbitai

coderabbitai Bot commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds post-backup maintenance to Taskfile.yaml that lists recent backups and removes files beyond the 30 most recent. Refactors docker/tools/Taskfile.obsidian.yaml: removes sync-vault-repo, adds stop-obsidian and start-obsidian, updates push-vault-repo to operate from VAULT_PATH and run pre-commit, and makes backup-vault-repo orchestrate stop → push → start.

Changes

Cohort / File(s) Summary
Backup cleanup
Taskfile.yaml
Adds post-backup output ("Recent backups:") and retention cleanup: lists the latest backups and deletes files older than the 30 most recent using timed sort + tail -n +31 with xargs rm.
Obsidian vault workflow refactoring
docker/tools/Taskfile.obsidian.yaml
Removes sync-vault-repo. Adds stop-obsidian and start-obsidian tasks. Updates push-vault-repo to cd into VAULT_PATH, run pre-commit run and re-add files before commit/push. Modifies backup-vault-repo to run stop → push → start (start invoked via defer).

Sequence Diagram

sequenceDiagram
    participant User
    participant BackupTask as backup-vault-repo
    participant Stop as stop-obsidian
    participant Push as push-vault-repo
    participant Start as start-obsidian
    participant Obsidian as ObsidianService
    participant Git as Git+pre-commit

    User->>BackupTask: run backup-vault-repo
    BackupTask->>Stop: invoke stop-obsidian
    Stop->>Obsidian: stop service
    BackupTask->>Push: invoke push-vault-repo
    Push->>Obsidian: cd to VAULT_PATH (operate on vault)
    Push->>Git: run pre-commit hooks
    Git-->>Push: hooks complete (may modify files)
    Push->>Push: git add (re-add after pre-commit), commit, push
    Push-->>BackupTask: push complete
    BackupTask->>Start: invoke start-obsidian (deferred)
    Start->>Obsidian: start service
    BackupTask-->>User: done
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Check shell commands in Taskfile.yaml for portability/safety (timed sort, xargs rm).
  • Review push-vault-repo sequence: correct cd to VAULT_PATH, placement of pre-commit run, and re-git add.
  • Ensure start-obsidian is correctly deferred in backup-vault-repo.

Possibly related PRs

Pre-merge checks and finishing touches

✅ 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 accurately summarizes the main changes: updating Obsidian Vault backup strategy and adding cleanup for old backups, matching the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/obsidian-backup

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
Taskfile.yaml (1)

139-142: Verify backup creation before cleanup and clarify repository comment.

The retention logic correctly keeps the 30 most recent backups. However, consider these points:

  1. The cleanup runs even if the tar command on line 138 fails, potentially removing old backups without creating a new one.
  2. The comment "they are still kept in the repository" is unclear since ../infra-config-backup appears to be outside the git repository.
🔎 Consider adding error handling:
  backup-config:
    desc: Create a compressed backup of the configuration directory
    cmds:
      - mkdir -p ../infra-config-backup
-     - cd config && tar -cjf "../infra-config-backup/infra-config-$(date +%Y-%m-%d_%H-%M-%S).tar.bz2" .
+     - |
+       cd config && tar -cjf "../infra-config-backup/infra-config-$(date +%Y-%m-%d_%H-%M-%S).tar.bz2" . || { echo "Backup creation failed"; exit 1; }
      - echo "Recent backups:"
      - ls -lh ../infra-config-backup/infra-config-*.tar.bz2 | tail -n 5
-     # Remove old backups (they are still kept in the repository - see the push-config-repo task)
+     # Remove old backups (keeping 30 most recent)
      - ls -t ../infra-config-backup/infra-config-*.tar.bz2 | tail -n +31 | xargs -r rm
docker/tools/Taskfile.obsidian.yaml (1)

44-49: Service may remain stopped if backup fails.

The orchestration correctly stops Obsidian before backing up to ensure data consistency. However, if stop-obsidian or push-vault-repo fails, the service will remain stopped because start-obsidian won't execute due to Task framework's default behavior of stopping on first error.

Consider using deferred commands, which run after all other commands even if the task fails:

  backup-vault-repo:
    desc: Stop Obsidian, commit and push changes to git, then start the service
    cmds:
      - task: stop-obsidian
      - defer: { task: start-obsidian }
      - task: push-vault-repo

Note: The defer directive ensures deferred tasks are executed in last-in-first-out order. This is available in Task v3.38.0 and later.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 31fe70b and 7c3f0d6.

📒 Files selected for processing (2)
  • Taskfile.yaml (1 hunks)
  • docker/tools/Taskfile.obsidian.yaml (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{yaml,yml}

📄 CodeRabbit inference engine (AGENTS.md)

YAML files must pass YAML linting and validation

Files:

  • Taskfile.yaml
  • docker/tools/Taskfile.obsidian.yaml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: check
🔇 Additional comments (3)
docker/tools/Taskfile.obsidian.yaml (3)

7-9: Good documentation of the separate git-dir approach.

The comments clearly explain why .git is placed outside the vault directory and provide a reference to the official documentation.


19-21: Pre-commit failures are silently ignored.

The || true on line 20 ensures the task continues even when pre-commit hooks fail. While this allows pre-commit to auto-fix files (captured by the second git add), it also means validation failures are silently ignored.

Consider whether you want to:

  • Keep this behavior to ensure backups always complete, or
  • Remove || true to enforce pre-commit validation

The current approach prioritizes backup completion over code quality checks. Verify this aligns with your requirements for the backup workflow.


34-42: Service lifecycle tasks look good.

The stop-obsidian and start-obsidian tasks provide clean abstractions for service management. These integrate well with the updated backup workflow.

@bubacoder
bubacoder force-pushed the feature/obsidian-backup branch from 7c3f0d6 to 22b5615 Compare December 18, 2025 06:19

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
Taskfile.yaml (2)

140-140: Handle the case when no backup files exist.

The ls command will fail with an error if no matching backup files exist, which could happen on first run or if the backup directory is empty.

🔎 Apply this diff to suppress errors when no files exist:
-      - ls -lh ../infra-config-backup/infra-config-*.tar.bz2 | tail -n 5
+      - ls -lh ../infra-config-backup/infra-config-*.tar.bz2 2>/dev/null | tail -n 5 || echo "No backups found."

142-142: Handle the case when no backup files exist.

Similar to line 140, the ls command will fail with an error if no matching backup files exist. While xargs -r prevents rm from running on empty input (good!), the ls itself will still output an error message.

🔎 Apply this diff to suppress errors when no files exist:
-      - ls -t ../infra-config-backup/infra-config-*.tar.bz2 | tail -n +31 | xargs -r rm
+      - ls -t ../infra-config-backup/infra-config-*.tar.bz2 2>/dev/null | tail -n +31 | xargs -r rm
docker/tools/Taskfile.obsidian.yaml (1)

16-21: LGTM! Pre-commit integration is correctly implemented.

The addition of pre-commit run with a second git add --all is the correct pattern, since pre-commit hooks may auto-fix files that need to be re-staged. The || true appropriately allows the workflow to continue even if pre-commit reports issues.

Minor consistency note: The trailing slash in VAULT_PATH construction (line 16) differs from the style used in push-config-repo task in Taskfile.yaml, which uses CONFIG_PATH="config" without a trailing slash. Consider removing the trailing slash for consistency:

-        VAULT_PATH="${STORAGE_OBSIDIAN}/${OBSIDIAN_VAULT_NAME}/"
+        VAULT_PATH="${STORAGE_OBSIDIAN}/${OBSIDIAN_VAULT_NAME}"
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c3f0d6 and 22b5615.

📒 Files selected for processing (2)
  • Taskfile.yaml (1 hunks)
  • docker/tools/Taskfile.obsidian.yaml (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{yaml,yml}

📄 CodeRabbit inference engine (AGENTS.md)

YAML files must pass YAML linting and validation

Files:

  • Taskfile.yaml
  • docker/tools/Taskfile.obsidian.yaml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: check
🔇 Additional comments (3)
docker/tools/Taskfile.obsidian.yaml (3)

7-9: LGTM!

The updated comment clearly explains the rationale for keeping the .git folder outside the vault and provides a helpful reference to the Git documentation.


34-42: LGTM!

The new service control tasks provide clear lifecycle management for the Obsidian service. The task descriptions are clear and the implementation is straightforward.


44-49: LGTM! Excellent use of defer for resilient service management.

The orchestration correctly stops Obsidian before committing changes and uses defer to ensure the service is restarted even if the push operation fails. This pattern provides good resilience and prevents leaving the service in a stopped state.

@bubacoder
bubacoder merged commit a7c3b01 into main Dec 18, 2025
4 checks passed
@bubacoder
bubacoder deleted the feature/obsidian-backup branch December 18, 2025 06:28
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