LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   crontab rsync backup across servers (https://www.linuxquestions.org/questions/linux-server-73/crontab-rsync-backup-across-servers-937949/)

secretlydead 04-03-2012 02:08 PM

crontab rsync backup across servers
 
Hi,

I'm trying to backup my server everyday. The first of these commands is not running in cron:

0 2 * * * /usr/bin/rsync -ab --backup-dir=/home/back/backup/site/old_`date +%F` --exclude=/admin/ppc/sos/reports/ --exclude=/admin/templates_c/ user@host:/home/user/public_html/ /home/back/backup/site/

10 2 * * * /usr/bin/rsync -ab user@host:/home/user/backup/ /home/back/backup/db


but BOTH of these commands work from the command line.

T3RM1NVT0R 04-03-2012 02:20 PM

@ Reply
 
Hi secretlydead,

Instead of mentioning the command you can create a small script for these commands. As you said that first one doesn't work but second one does so it appears that the command is getting truncated when cron tries to execute.

Better is to create a file say backup.sh and put the first command in there and then put an entry for that script in cron and it should work.

colucix 04-03-2012 02:35 PM

As T3RM1NVT0R suggested, better to create a script and run it from crontab. Anyway, the problem is the % sign in the date format, that has a special meaning in crontab. From man 5 crontab:
Quote:

Percent-signs (%) in the command, unless escaped with backslash (\), will
be changed into newline characters, and all data after the first % will
be sent to the command as standard input.
Escaping it should do the trick.


All times are GMT -5. The time now is 01:26 AM.