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/*
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:
You're testing against the variable
$CANT
which isn't set anywhere.I wonder if
ulimit -t
is getting in your way.It might be a permission problem; is the crontab entry under the same user that can run the script successfully from the command line ?