Hi. I get an error when I try to call this shell from crontab. I can run this script manually without problem, but it just doesn't work with cron.
backup.sh
I'm using FreeBSD 9.3. My
and I tried adding
backup.sh
Code:
#!/bin/sh
# Get mode from user input
# Allowed modes:
# all: backups account, common, log, player, webserver
# game: backups account, common, player
# gameLog: backups log
# web: backups webserver
# exceptLog: backups account, common, player, webserver
MODE=$1
if [ "$MODE" == "" ]; then
MODE="exceptLog"
fi
# Bins
MYSQLDUMP=`which mysqldump`
GZIP=`which gzip`
NCFTP=`which ncftp`
# Date for folders and filenames
DAY=$(date +"%Y-%m-%d")
FILETIME=$(date +"%Y-%m-%d.%T")
# Local backup folder (no trailing slash)
LOCAL_FOLDER="/tmp/backup"
# FTP Configuration
REMOTE_HOST="####"
REMOTE_USER="####"
REMOTE_PASS="####"
REMOTE_FOLDER="/backup/####/" # With trailing slash
# MySQL Configuration
MYSQL_USER="####"
MYSQL_PASS="####"
# Which databases shall we backup?
# Databases should be separated with a space
DATABASES=""
if [ "$MODE" == "all" ]; then
DATABASES="account common log player webserver"
elif [ "$MODE" == "game" ]; then
DATABASES="account common player"
elif [ "$MODE" == "gameLog" ]; then
DATABASES="log"
elif [ "$MODE" == "web" ]; then
DATABASES="webserver"
elif [ "$MODE" == "exceptLog" ]; then
DATABASES="account common player webserver"
fi
# Check if DATABASES var is set...
if [ "$DATABASES" == "" ]; then
echo -e "\033[31mThe specified mode doesn't exist...\033[0m"
exit 1
fi
# Dump and compress
for db in $DATABASES
do
FILE=$db.$FILETIME.gz
echo -e "\033[32mDumping $db!\033[0m"
$MYSQLDUMP -u $MYSQL_USER -p$MYSQL_PASS $db | $GZIP -9 > $LOCAL_FOLDER/$FILE
done
# Transfer all backup files to remote host
echo -e "\033[32m\nTransfering files!\033[0m"
$NCFTP -u$REMOTE_USER -p$REMOTE_PASS $REMOTE_HOST<<EOF
mkdir $REMOTE_FOLDER$DAY
cd $REMOTE_FOLDER$DAY
lcd $LOCAL_FOLDER
mput *
quit
EOF
# Delete local dump files
rm -f $LOCAL_FOLDER/*
I'm using FreeBSD 9.3. My
crontab -l output is
Code:
* * * * * /usr/home/backup.sh
Code:
* * * * * sh /usr/home/backup.sh