Rsync has three ways to decide if a file is outdated:
- Compare size of files
- Compare timestamps
- Compare static checksums
So we can choose --size-only, --ignore-times or ---checksum option in order to decide how to compare files.
Let's write little example
- Let's create some directory and write some files in it. The idea is the following: if we add any files in the directory , remote devices will revieve that files (any devices who have rsync client)
mkdir /opt/{my_app_settings}/dev/
- Edit rsyncd.conf file and write configurations. I have created 2 configuration. But before editing the file imagine that some remote devices mught need to revieve files from different directory. We have already created directory named "dev" but we can also can create another directory. For example let's create another directory named "prod". So rsync client will decide which directory to use - in the other words where to get files. So our configuration looks like that:
[dev] path = /opt/{my_app_settings}/dev read only = true uid = root gid = root [prod] path = /opt/{my_app_settings}/prod read only = true uid = root gid = root
- Run rsync daemon
rsync --daemon
- Run rsync client in order to retrieve new files:
rsync -rtv root@IP::dev {destionation_directory}
Also we can create sheduler in order to execute auto synchronization.
crontab -e
If you want to run cron job every 1 minute, write the following cron config
- Cron examples
Every 1 minute * * * * * Every 15 minutea */15 * * * * Every 30 minutes */30 * * * * Every 1 hour 0 * * * * Every 6 hours 0 */6 * * * Every 12 hours 0 */12 * * * Once a day 4 0 * * * Once a week 4 0 * * 0 Once a month 4 0 1 * *
Now just verify your cron job
crontab -lResults should be something like that: