Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 04-03-2012, 02:08 PM   #1
Registered: Sep 2003
Location: Qingdao, China
Distribution: mandriva, slack, red flag
Posts: 249

Rep: Reputation: 31
crontab rsync backup across servers


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.
Old 04-03-2012, 02:20 PM   #2
Senior Member
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ 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 and put the first command in there and then put an entry for that script in cron and it should work.
Old 04-03-2012, 02:35 PM   #3
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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:
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Rsync Backup for Windows, Linux Knoppix, and Other Smart Technologies in Handy Backup by Novos LXer Syndicated Linux News 0 12-24-2011 11:43 AM
[SOLVED] rsync execution issue with crontab - Have given full path to rsync too!! Prabagaran Linux - Server 6 04-15-2011 01:39 AM
LXer: Backup with rsync and LXer Syndicated Linux News 0 09-14-2010 04:20 PM
Crontab rsync does not backup to NAS device Astol Linux - Software 1 09-24-2008 12:04 AM
Backup with rsync and crontab gjblackford Linux - General 4 01-04-2007 08:53 AM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:17 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration