Please I get error whenever I run this MySQL database backup cron job bash script. Can someone please tell me what's wrong with this code:
Code:
#!/bin/sh
# List of databases to be backed up separated by space
dblist="Forum_base"
# Directory for backups
backupdir=/root/mysql_backups/daily
# Number of versions to keep
numversions=7
# Full path for MySQL hotcopy command
# Please put credentials into /root/.my.cnf
#hotcopycmd=/usr/bin/mysqlhotcopy
hotcopycmd="/usr/bin/mysqldump --lock-tables --databases"
# Create directory if needed
mkdir -p "$backupdir"
if [ ! -d "$backupdir" ]; then
echo "Invalid directory: $backupdir"
exit 1
fi
# Hotcopy begins here
echo "Dumping MySQL Databases..."
RC=0
for database in $dblist; do
echo
echo "Dumping $database ..."
mv "$backupdir/$database.gz" "$backupdir/$database.0.gz" 2> /dev/null
$hotcopycmd $database | gzip > "$backupdir/$database.gz"
RC=$?
if [ $RC -gt 0 ]; then
continue;
fi
# Rollover the backup directories
rm -fr "$backupdir/$database.$numversions.gz" 2> /dev/null
i=$numversions
while [ $i -gt 0 ]; do
mv "$backupdir/$database.`expr $i - 1`.gz" "$backupdir/$database.$i.gz" 2> /dev/null
i=`expr $i - 1`
done
done
if [ $RC -gt 0 ]; then
echo "MySQL Dump failed!"
exit $RC
else
# Hotcopy is complete. List the backup versions!
ls -l "$backupdir"
echo "MySQL Dump is complete!"
fi
exit 0
This is the errors that I'm getting:
Code:
-bash-3.2# sh /etc/cron.daily/mysqlbackup.sh
: command not founde 2:
: command not founde 5:
: command not founde 8:
: command not founde 11:
: command not founde 16:
'ysqlbackup.sh: line 27: syntax error near unexpected token `do
'ysqlbackup.sh: line 27: `for database in $dblist; do