WatchSync is a lightweight utility written in C that monitors local directories and synchronizes changes in real-time to a remote server using rsync. It is designed to be efficient, easy to configure, and compatible with development and system administration workflows.
Author: Toni Garcia
- Real-time Synchronization: Uses
inotifyto detect changes instantly. - Daemon Mode: Can run in the background as a system service.
- Flexible Configuration: Supports multiple "jobs" with global configuration inheritance.
- Secure: Uses
mkstempfor temporary files and supports internal password management forsshpass. - Permission Checks: Refuses to run with insecurely configured files (e.g., world-readable passwords).
- Lightweight: Written in pure C with minimal dependencies.
- GCC or another C compiler.
rsyncinstalled on both local and remote machines.sshpass(optional, for automated password-based sync).- Linux system (uses
inotify).
- Clone the repository or download the source.
- Build the project:
make
- Install binaries and basic configuration files:
Note: Default permissions for configuration will be set to be restricted.
sudo make install
/etc/watchsync.conf: Global configuration. Definersync.*andexcludeoptions here to be inherited by all jobs./etc/watchsync.d/: Directory for job-specific configurations. Each file in this directory defines a synchronization job.
| Variable | Description | Scope |
|---|---|---|
local.root |
Local directory to monitor | Local |
remote.user |
Remote server username | Local |
remote.host |
Remote server address | Local |
remote.root |
Destination directory on the remote server | Local |
remote.password |
Password for the remote user (requires sshpass) |
Local |
rsync.delete |
If true, delete files on remote not present locally |
Global/Local |
rsync.delay_ms |
Wait time after the last event before launching rsync (ms) | Global/Local |
exclude |
Exclusion pattern (one per line) | Global/Local |
Configuration files and the /etc/watchsync.d/ directory must not be accessible by group or others (e.g., permissions should be 0600 or 0700). The utility will refuse to load insecure configurations.
local.root = /home/user/progs/my_app
remote.user = dev
remote.host = server.example.com
remote.root = /var/www/my_app
remote.password = s3cr3t
# Override global inheritance if needed
rsync.delay_ms = 300
exclude = .git
exclude = vendorRun watchsync with a specific configuration file in the foreground:
$ watchsync -c ./my_config.conf
[cli] === RSYNC START ===
[cli] <f.st...... User_Manual.md
[cli] <f.st...... README.md
[cli] <f.st...... src/Controller/Authentication/LoginController.php
[cli] === RSYNC OK ===
Note: If remote.password is not defined in the configuration file, you will be securely prompted to enter it.
To run all jobs defined in /etc/watchsync.d/ in the background:
sudo watchsync -d- Copy the service file:
sudo cp etc/watchsync.service /etc/systemd/system/ - Start the service:
sudo systemctl daemon-reload sudo systemctl enable watchsync sudo systemctl start watchsync
- Server Synchronization: Maintain an exact mirror of a configuration or assets directory between two servers.
- Remote Development: Edit files locally with your favorite IDE and let
watchsyncupload them to the test server instantly. - Continuous Backup: Sync important documents to a NAS or backup server as they are modified.
Contributions are welcome! Feel free to open an Issue or a Pull Request for performance improvements, new change detection backends, better error handling, or alternative authentication methods (e.g., SSH keys, different vault integrations).
This project is licensed under the MIT License.