How to schedule Rsync via cron job
Schedule Rsync to run using cron jobs.
Using cron jobs you can schedule Rsync to run periodically.
This is the scheduling syntax of a cron job:
+---------------- the minutes (0 - 59)
| +------------- the hours (0 - 23)
| | +---------- the days in a month (1 - 31)
| | | +------- the month (1 - 12)
| | | | +---- the day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command
Let's open
crontab
to create a new cron job. Choose what editor you want to use; for our examples, we're using
nano
.
$ crontab -e
When ready, the crontab file can be edited:
Let's setup a cron job that runs every Monday at 10:45 PM. Our command will sync
directory1
to
directory2
using Rsync:
45 22 * * 1 rsync -av /home/ubuntu/directory1 /home/ubuntu/directory2
The command above means that the Rsync syncronization will start at the 45th minute of the 22nd hour of the first day of each week (Monday).