rsync/cron

General support questions
Post Reply
portnoy
Posts: 6
Joined: 2015/09/14 11:49:29

rsync/cron

Post by portnoy » 2017/12/12 12:03:13

I've searched the archives for help with this, a couple of things came close but did not help me.

I was running a weekly cron job that sent some files to backup to an offsite server. It was working well, so I thought I should try to do it every day for a more robust backup solution, and that's where I got hung up. I want to backup to to a directory based on the day of the week, it seems cron doesn't like that since the exact same command works from the command line. Here is the line from cron:

Code: Select all

/usr/bin/rsync -avzhe "ssh -p 222" --exclude-from '/home/laca/exclude.jb' /mnt/tom1/backups/jbserver/jbserver laca@****.dyndns.org:/media/laca/`/bin/date +\%A`/
The only thing different between this line and the weekly cron job that works is the "/bin/date" part, so I'm assuming that is the sticky point, but I can't figure out how else to do it. If I don't escape the "%" in the date line it fails immediately. If I slap an "echo" at the front of the cron job, I get this, which correctly uses the DOTW as the directory:

Code: Select all

/usr/bin/rsync -avzhe ssh -p 222 --exclude-from /home/laca/exclude.jb /mnt/tom1/backups/jbserver/jbserver laca@****.dyndns.org:/media/laca/Monday/
Any help appreciated.

tunk
Posts: 424
Joined: 2017/02/22 15:08:17

Re: rsync/cron

Post by tunk » 2017/12/12 12:28:48

I don't really know, but do these directories (Monday etc) exist on ****.dyndns.org?

portnoy
Posts: 6
Joined: 2015/09/14 11:49:29

Re: rsync/cron

Post by portnoy » 2017/12/12 12:38:36

tunk wrote:I don't really know, but do these directories (Monday etc) exist on ****.dyndns.org?
That is my home server's address thru dyndns. Running the command thru the shell creates the directory, it does not thru cron.

portnoy
Posts: 6
Joined: 2015/09/14 11:49:29

Re: rsync/cron

Post by portnoy » 2017/12/13 11:29:38

I put the 1st code line below into a script in the user's /home directory, made a DOTW variable in the script (so as not to have to escape anything) and called the script from cron, everything worked fine.

portnoy wrote:I've searched the archives for help with this, a couple of things came close but did not help me.

I was running a weekly cron job that sent some files to backup to an offsite server. It was working well, so I thought I should try to do it every day for a more robust backup solution, and that's where I got hung up. I want to backup to to a directory based on the day of the week, it seems cron doesn't like that since the exact same command works from the command line. Here is the line from cron:

Code: Select all

/usr/bin/rsync -avzhe "ssh -p 222" --exclude-from '/home/laca/exclude.jb' /mnt/tom1/backups/jbserver/jbserver laca@****.dyndns.org:/media/laca/`/bin/date +\%A`/
The only thing different between this line and the weekly cron job that works is the "/bin/date" part, so I'm assuming that is the sticky point, but I can't figure out how else to do it. If I don't escape the "%" in the date line it fails immediately. If I slap an "echo" at the front of the cron job, I get this, which correctly uses the DOTW as the directory:

Code: Select all

/usr/bin/rsync -avzhe ssh -p 222 --exclude-from /home/laca/exclude.jb /mnt/tom1/backups/jbserver/jbserver laca@****.dyndns.org:/media/laca/Monday/
Any help appreciated.

Post Reply