Create a Log file for Rsync if not exists
Okay so after good guidance by the coolest people who answered below I was able to solve this problem. Actually the problem was that if you use --log-file
with rsync
and provide the logfile a directory which does not exist it will give you an error that the log file does not exist.
But if the provided directory exists then the logfile is automatically created within the provided directory. Here is the updated syntax I am using
mkdir -p -v $HOME/public_html/rsynclogs/rsync -azP --stats source-directory user@host.com:destination-directory --log-file=$HOME/public_html/rsynclogs/rsync-backup-log-$(date +"%Y-%m-%d").log
Now mkdir creates a directory. As suggested by @janek I added -p just so it checks if the directory exists and only creates if it does not exist.
Other Updates in Syntax:
Replaced ~
with $HOME
. Suggested by @l'L'l
Replaced backticks(``)
with $( ... )
. Suggested by @l'L'l