I am setting up rsync cron to run every hour to sync up 2 servers. My question is how do I make the log file name that it is saving to in the format log_file-{Year}-{Month}-{Date}.log with the year, month, and date changing accordingly?

Thanks in advance.


I assume you're using --log-file? Then you can do something like this:

date=`date +%Y-%m-%d`
rsync --log-file=log_file-$date (...)

Or, in a single line if you're putting this directly in your crontab:

rsync --log-file=log_file-`date +%Y-%m-%d` (...)
  • Based on what I see from the system cron log, this is what is being ran rsync -av --log-file=/home/backup/rsync/rsync-`date +. Looks like it is hanging up on the + – Tom May 31 '11 at 18:48
  • 2
    Try this: rsync --log-file=log_file-$(date +%Y-%m-%d) (...). You're probably better off creating a backup.sh and putting the whole procedure there - it's cleaner and lets you move to a more complex or multi-step backup procedure easily. – Eduardo Ivanec May 31 '11 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.