feat: implement daemon mode with filesystem watching
All checks were successful
check / check (pull_request) Successful in 4m57s

Replace the daemon mode stub with a full implementation that:

- Watches configured snapshot paths for filesystem changes using
  fsnotify (inotify on Linux, FSEvents on macOS, etc.)
- Runs an initial full backup on startup
- Triggers incremental backups at backup_interval when changes are
  detected, only for snapshots whose paths were affected
- Performs full periodic scans at full_scan_interval regardless of
  detected changes
- Respects min_time_between_run to prevent excessive backup runs
- Handles SIGTERM/SIGINT for graceful shutdown, completing any
  in-progress backup before exiting
- Automatically watches newly created subdirectories
- Uses a backup semaphore to prevent concurrent backup runs

New files:
- internal/vaultik/daemon.go: RunDaemon(), changeTracker, watcher setup
- internal/vaultik/daemon_test.go: Tests for changeTracker, isSubpath,
  concurrency safety, and daemon constants

closes #3
This commit is contained in:
user
2026-03-24 09:48:06 -07:00
parent 65da291ddf
commit 07a31a54d4
7 changed files with 646 additions and 21 deletions

28
TODO.md
View File

@@ -106,23 +106,21 @@ User must have rclone configured separately (via `rclone config`).
---
## Post-1.0 (Daemon Mode)
## Daemon Mode (Complete)
1. Implement inotify file watcher for Linux
- Watch source directories for changes
- Track dirty paths in memory
1. [x] Implement cross-platform filesystem watcher (via fsnotify)
- Watches source directories for changes
- Tracks dirty paths in memory
- Automatically watches new directories
1. Implement FSEvents watcher for macOS
- Watch source directories for changes
- Track dirty paths in memory
1. [x] Implement backup scheduler in daemon mode
- Respects backup_interval config
- Triggers backup when dirty paths exist and interval elapsed
- Implements full_scan_interval for periodic full scans
- Respects min_time_between_run to prevent excessive runs
1. Implement backup scheduler in daemon mode
- Respect backup_interval config
- Trigger backup when dirty paths exist and interval elapsed
- Implement full_scan_interval for periodic full scans
1. Add proper signal handling for daemon
1. [x] Add proper signal handling for daemon
- Graceful shutdown on SIGTERM/SIGINT
- Complete in-progress backup before exit
- Completes in-progress backup before exit
1. Write tests for daemon mode
1. [x] Write tests for daemon mode