But i cant get this to work
Is it possible?
#!/bin/sh
# This script will backup one or more mySQL databases
# and then optionally email them and/or FTP them
# This script will create a different backup file for each database by day of the week
# i.e. 1-dbname1.sql.gz for database=dbname1 on Monday (day=1)
# This is a trick so that you never have more than 7 days worth of backups on your FTP server.
# as the weeks rotate, the files from the same day of the prev week are overwritten.
################################################## ##########
#===> site-specific variables - customize for your site
# List all of the MySQL databases that you want to backup in here,
# each seperated by a space
databases="nameofdatabase"
# Directory where you want the backup files to be placed
backupdir=~
# MySQL dump command, use the full path name here
mysqldumpcmd=/usr/bin/mysqldump
# MySQL Username and password
userpassword=" --user=root --password=********"
# MySQL dump options
dumpoptions=" --quick --add-drop-table --add-locks --extended-insert --lock-tables"
# Unix Commands
gzip=/bin/gzip
#uuencode=/usr/bin/uuencode
mail=/bin/mail
# Send Backup? Would you like the backup emailed to you?
# Set to "y" if you do
sendbackup="n"
subject="mySQLBackup"
mailto="yourname@domain.com"
#===> site-specific variables for FTP
ftpbackup="n"
ftpserver="ftp.domain.com"
ftpuser="username"
ftppasswd="********"
# If you are keeping the backups in a subdir to your FTP root
ftpdir="/public_ftp/incoming"
#===> END site-specific variables - customize for your site
################################################## ##########
# Get the Day of the Week (0-6)
# This allows to save one backup for each day of the week
# Just alter the date command if you want to use a timestamp
DOW=`date +%w`
# Create our backup directory if not already there
mkdir -p ${backupdir}
if [ ! -d ${backupdir} ]
then
echo "Not a directory: ${backupdir}"
exit 1
fi
# Dump all of our databases
echo "Dumping MySQL Databases"
for database in $databases
do
$mysqldumpcmd $userpassword $dumpoptions $database > ${backupdir}/${DOW}-${database}.sql
done
# Compress all of our backup files
echo "Compressing Dump Files"
for database in $databases
do
rm -f ${backupdir}/${DOW}-${database}.sql.gz
$gzip ${backupdir}/${DOW}-${database}.sql
done
# FTP it to the off-site server
if [ $ftpbackup = "y" ]
then
for database in $databases
do
echo "==> ${backupdir}/${DOW}-${database}.sql.gz"
ftp -n $ftpserver <<EOF
user $ftpuser $ftppasswd
bin
prompt
cd $ftpdir
lcd ${backupdir}
put ${DOW}-${database}.sql.gz
quit
EOF
done
echo "FTP file send to $ftpserver FTP server"
fi
# Send the backups via email
if [ $sendbackup = "y" ]
then
for database in $databases
do
echo "Trying to send mail"
$uuencode ${backupdir}/${DOW}-${database}.sql.gz ${backupdir}/${DOW}-${database}.sql.gz | $mail $subject $mailto
echo "Mail sent!"
done
fi
# And we're done
echo "Dump Complete!"
exit