[PLUG] Cron advice needed

David dafr+plug at dafr.us
Tue Apr 26 20:13:43 UTC 2016


On 04/26/2016 10:45 AM, John Jason Jordan wrote:
> On Sat, 23 Apr 2016 09:36:31 -0700
> Galen Seitz <galens at seitzassoc.com> dijo:
>
>> On 04/23/16 09:22, John Jason Jordan wrote:
>>> Using Russel's advice and yours above I created the crontab (using
>>> nano) and added the following command:
>>>
>>> 	0 3 * * * cp -auf /home/jjj/Mail /media/jjj/Data/
>>>

<clip>

>
> OK, I figured out that the crontab file is where it's supposed to be.
> But now I have another problem. The command
>
> 	0 3 * * * cp -auf /home/jjj/Mail /media/jjj/Data/Mail
>
> Worked the first time I ran it, but not subsequent times, i.e., it's
> like it finds the data folders are already there and won't overwrite
> them. I first realized this when I checked and the Mail folder had not
> been changed by the 3am cron job. So I tried running the above
> command (just the actual command) manually from the command line and,
> again, it did nothing. Then I deleted the backup Mail folder completely
> and ran the command again. This time it copied the ~/Mail folder
> to /media/Data/Mail.
>
> According to man cp -auf is what I should be using for what I want the
> command to so, but apparently there is something that I am not
> understanding.

Once you start getting more complex commands, it's sometimes better to 
move them out of cron directly. I would suggest that you build a shell 
script that works as you wish, then put that into place in cron.

Something like this should work for you:


      0 3 * * * /bin/bash /home/jjj/bin/mail-sync.sh

You'll have to adjust names and pathing accordingly.

In the script, you can have variables, comments, and other "gee whiz" 
kind of stuff.

If the cp command is giving you grief (a quick read of the man page 
suggests -u might be a possible culprit), and if you know how to use 
rsync, you might just switch to that and move on with your day.

Based on the command provided above, your execution line might even be 
as simple as this:

      rsync -a /home/jjj/Mail /media/jjj/Data/Mail

Of course, I don't have access to your system to verify that this would 
be proper syntax, but it won't be far from it. Additionally, in your 
script, you can create modifications such as multiple iterations of the 
backup, change names, and more, which would allow you to roll back 
farther than just one day if needed.

If you need/want help with writing something like that, I might be able 
to spend a few minutes chatting with you and/or providing a rudimentary 
script.

dafr




More information about the PLUG mailing list