Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

everybody! Maybe you can help me with this: I have set up my daily backup rotation in Cron to run every day at 4 am. The script is not complicated (see below), and when I execute it myself it works without problem. However, when I schedule it on Cron, the script runs for about half an hour and then stops (no mail, no warning, it just stops copying files at some point).

Any ideas about why this could be happening? The backup folder is about 38Gb big, and it takes almost an hour for the script to run. I'm guessing some kind of run-time limitation, but is just an idea.

Last, but not least, this is the script. It keeps an "archive" folder with 7 daily backups:

#!/bin/bash
NEW=`date +%Y%m%d`
NUMBER=7

function erase_old()
{
    while (( $# > $NUMBER )); do
        rm -rf "$1"
        shift
    done
}

mkdir /backup/archive/$NEW
cp -vrp /backup/current/* /backup/archive/$NEW
erase_old /backup/archive/*
share|improve this question
    
how do you know it stops without warning and with an error? you are not writing any log. have you checked your diskspace? –  Christian Jan 12 '10 at 13:30
    
Sadly, I did check for diskspace, and there is plenty of it available. As for the logging, I set Cron to send me emails about the run results, but I agree with you about adding some extra logging –  Martin Jan 12 '10 at 15:20

3 Answers 3

up vote 1 down vote accepted

Not sure why it's dying, but may I suggest an alternative approach to your rolling backups?

Try using instead of today's date, today's day for the file name. Then you never have to delete the old ones, they will just get overwritten. (Or you could delete <today>, and then write the new one.)

To get's today's value, do something like:

$FNAME=`date +%A`
share|improve this answer
1  
The problem went as misteriously as it came, but I'm marking your answer as the accepted one because your idea is a good one –  Martin Jan 14 '10 at 18:18
    
thanks for the accept. Happy the issue went away :) –  warren Jan 17 '10 at 14:03

You're testing against the variable $CANT which isn't set anywhere.

I wonder if ulimit -t is getting in your way.

share|improve this answer
    
Sorry about that, actually $CANT is $NUMBER, but i forgot to rename it when I asked the question (I renamed the variables, "CANT" stands from "cantidad" - "quantity" in spanish). BTW, "ulimit -t" returns "unlimited" –  Martin Jan 12 '10 at 15:04

It might be a permission problem; is the crontab entry under the same user that can run the script successfully from the command line ?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.