Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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` (...)
share|improve this answer
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
Try this: rsync --log-file=log_file-$(date +%Y-%m-%d) (...). You're probably better off creating a 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 posting your answer, you agree to the privacy policy and terms of service.

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