Erik Olof Wahlstrom schrieb:
Hello - I am having a problem with a backup script that I have put together -
when I run it as root from the terminal, it works as expected (with one
caveat); however, when cron runs it, the daily backup folder is created but
no files are deposited into that folder...
Here is the script:
#!/bin/bash
BACKUP_DIR="/media/disk/AUTOMATED_BACKUPS/DB_DAILY"
CURRENT_DIR=$BACKUP_DIR/`date +%d`
DATABASES="$(/usr/bin/mysql -uUsername -pPassword -Bse 'show databases')"
echo 'Backing up databases: '$DATABASES
if [ -e "$CURRENT_DIR" ]
then
cd $CURRENT_DIR
/bin/rm *
else
/bin/mkdir $CURRENT_DIR
cd $CURRENT_DIR
fi
for DB in $DATABASES
do
/usr/bin/mysqldump -uroot -pHardAsMySql321 "$DB" | bzip2 >
"$DB"_`date +%Y-%m-%d_%k.%M`".sql.bz2"
done
exit 0
Can any skilled eyes see why this doesn't work when it is run from the roots
crontab?
The reason may be that crontab commands are run with "/bin/sh -c
command" (Bourne shell mode). Try changing the crontab entry to
"/bin/bash command".
Additionally, when I run the script as root in the terminal, I get the
following output:
Backing up databases: information_schema db1 db2 db3
/bin/rm: cannot remove `*': No such file or directory
Is there a better way to clear out last months files before making the
current backups?
You could replace the whole if-then-else clause by
mkdir -p $CURRENT_DIR
cd $CURRENT_DIR
rm -f *
provided the options are supported on your system.
Regards,
Bernd
--
Bernd Eggink
http://sudrala.de