Backup MySQL, Web server Files to a FTP Server Automatically


#!/bin/sh   
# System + MySQL backup script   
# Full backup day - Sun (rest of the day do incremental backup)   
# Copyright (c) 2005-2006 nixCraft   
# This script is licensed under GNU GPL version 2.0 or above   
# Automatically generated by http://bash.cyberciti.biz/backup/wizard-ftp-script.php   
# ---------------------------------------------------------------------</p>
<p>### System Setup ###   
DIRS="/etc /home"   
BACKUP=/tmp/backup.$$   
NOW=$(date +"%d-%m-%Y")   
INCFILE="/root/tar-inc-backup.dat"   
DAY=$(date +"%a")   
FULLBACKUP="Sun"
### MySQL Setup ###   
MUSER="root"   
MPASS="password"   
MHOST="localhost"   
MYSQL="$(which mysql)"   
MYSQLDUMP="$(which mysqldump)"   
GZIP="$(which gzip)"
### FTP server Setup ###   
FTPD="/test/incremental"   
FTPU="user"   
FTPP="password"   
FTPS="192.168.1.100"   
NCFTP="$(which ncftpput)"
### Other stuff ###   
EMAILID="name@acme.com"
### Start Backup for file system ###   
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :
### See if we want to make a full backup ###   
if [ "$DAY" == "$FULLBACKUP" ]; then   
FTPD="/test/full"   
FILE="fs-full-$NOW.tar.gz"   
tar -zcvf $BACKUP/$FILE $DIRS   
else   
i=$(date +"%Hh%Mm%Ss")   
FILE="fs-i-$NOW-$i.tar.gz"   
tar -g $INCFILE -zcvf $BACKUP/$FILE $DIRS   
fi</p>
### Start MySQL Backup ###   
# Get all databases name   
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"   
for db in $DBS   
do   
FILE=$BACKUP/mysql-$db.$NOW-$(date +"%T").gz   
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE   
done
### Dump backup using FTP ###   
#Start FTP backup using ncftp   
ncftp -u"$FTPU" -p"$FTPP" $FTPS<$T   
echo "Hostname: $(hostname)" >>$T   
echo "Backup failed" >>$T   
mail  -s "BACKUP FAILED" "$EMAILID" <$T   
rm -f $T   
fi   

Poi lo scheduli con il cron:
13 0 * * * /home/admin/bin/ftpbackup.sh >/dev/null 2>&1

Backup script generator:

http://bash.cyberciti.biz/backup/wizard-ftp-script.php

via