A daemon script that continuously pulls or pushes files between a remote server and local directories using rsync over SSH.
- Continuous Sync: Loops indefinitely based on a configurable interval.
- Modular Configuration: Support for global defaults and per-host property files.
- Dependency Checks: Verifies
rsyncandsshare installed locally and on the remote host. - Smart Excludes: Supports global, host-specific, and job-specific exclude files.
- Single Instance Protection: Uses a PID file to prevent multiple instances from running.
- SSH Config Friendly: Works seamlessly with
~/.ssh/configaliases.
- Initial Run: Run the script to check for missing dependencies and global files:
./autosync.sh
- Configuration:
- Copy
global.properties.templatetoglobal.propertiesand edit your defaults. - Copy
autosync.excludes.templatetoautosync.excludesfor global rsync filters.
- Copy
- Add Hosts: Place
.propertiesfiles in theconfigs/directory.
You can run autosync as a background service managed by systemd for your specific user. This ensures it starts automatically on login and restarts if it fails.
- Install the service:
./autosync.sh --setup-service
- Start the service:
systemctl --user start autosync.service
- Management Commands:
- View Status:
systemctl --user status autosync.service - View Logs:
journalctl --user -u autosync.service -f - Stop Service:
systemctl --user stop autosync.service
- View Status:
...
Set global defaults for connections and logging:
log_level: Set toerror(default) orinformationfor more detailed logs.log_max_size_kb: Max size of the log file before rotation.log_backups: Number of rotated backups to keep.
Define host-specific settings or sync jobs. Every .properties file in configs/ is loaded.
description="Production Web Server"
remote_ip="web01"
remote_user="deploy"
# Sync jobs: "direction,host_alias,local_path,remote_path,exclude_file,options"
synced_folder1="pull,,/var/www/html,/var/www/html,,delete"If a file named hostname.exclude exists in configs/ (where hostname matches the .properties filename), it is automatically applied to all jobs for that host.
The script supports .ssh/config. If you leave ssh_key and remote_port empty, it will use your system defaults for the given remote_ip.
- Local:
rsync,ssh - Remote:
rsyncmust be installed on the target machine.
- Logs:
logs/autosync.log(stdout) andlogs/autosync.err(rsync errors). - PID File:
logs/autosync.pidensures only one instance runs. - Stop the daemon:
kill $(cat logs/autosync.pid)