No need to be a Linux user to follow this guide : it is totally platform-independent. I will guide you through all the steps to install this script.

1 Prepare your server

Using a SSH client, connect to your server and check Cron :

$ crontab -l
no crontab for username

If you get this message, it's OK. If you got an error, forget about performing scheduled backups. You can still install the script and execute it manually, but it won't be possible to schedule automatic backups with Cron.

Prepare your server for the installation : create 2 directories and set restrictive access rights :

$ mkdir backup script
$ chmod 700 backup script

Visitors will have a "403 Access forbidden" error when attempting to visit these directories. You can also use a .ht_access file instead of chmod to deny access.

2 Download and edit the files

Dowload the files send_mail.pl, backup_mail.sh and my_crontab and edit backup_mail.sh using a text editor (wordpad for instance, avoid notepad)

#!/bin/bash

# Don't forget to escape special characters (as spaces) with \
DIR_BLOG="<path_to_your_blog>" # exemple : public_html/dotclear, or ./ for all your site
DIR_BACKUP="<path_to_backup_directory>" # exemple : backup

SQL_HOST="<your_mysql_server>"
SQL_USER="<your_mysql_login>"
SQL_PASS="<your_mysql_password>"
SQL_BASE="<your_mysql_database>"

CURRENTDATE=$(date +%Y%m%d)

MAIL_FROM="backup@<your_domain>"
MAIL_TO="<your_email_address>"
MAIL_SUBJECT="[$CURRENTDATE] Backup of ${DIR_BLOG} and SQL database"
MAIL_MESSAGE="Please find attached the backup of ${DIR_BLOG} for $CURRENTDATE"

DBDUMP_FILENAME="sql$CURRENTDATE.sql"

echo "Exporting database..."
touch $DIR_BACKUP/$DBDUMP_FILENAME && mysqldump -h $SQL_HOST -u $SQL_USER \
	--password=$SQL_PASS $SQL_BASE > $DIR_BACKUP/$DBDUMP_FILENAME

echo "Compressing export file..."
tar czf $DIR_BACKUP/$DBDUMP_FILENAME.tar.gz $DIR_BACKUP/$DBDUMP_FILENAME

echo "Creating global archive..."
tar czf $DIR_BACKUP/blog$CURRENTDATE.tar.gz $DIR_BLOG $DIR_BACKUP/$DBDUMP_FILENAME.tar.gz

echo "Mailing archive to $MAIL_TO..."

# Comment out this line if you use mutt
#echo $MAIL_MESSAGE | mutt -s $MAIL_SUBJECT -a $DIR_BACKUP/blog$CURRENTDATE.tar.gz $MAIL_TO

# Comment out these lines if you use uuencode & mail
#(echo $MAIL_MESSAGE ; uuencode -m $DIR_BACKUP/blog$CURRENTDATE.tar.gz blog$CURRENTDATE.tar.gz) \
#	| mail -s $MAIL_SUBJECT $MAIL_TO

# Comment out these lines if you want to use Perl MIME::Lite (works for 1&1 host)
perl script/send_mail.pl "${MAIL_FROM}" "${MAIL_TO}" "${MAIL_SUBJECT}" "${MAIL_MESSAGE}" \
	$DIR_BACKUP/blog$CURRENTDATE.tar.gz blog$CURRENTDATE.tar.gz

echo "Deleting temporary files..."
rm -f $DIR_BACKUP/$DBDUMP_FILENAME*

echo "Backup completed in $DIR_BACKUP/blog$CURRENTDATE.tar.gz"

Modify the SQL_*, DIR_* and MAIL_* variables as needed.

Edit my_crontab and schedule the backups :

For a weekly backup every tuesday at 4.54am, we should use :

54 4 * * tue script/backup_mail.sh >/dev/null 2>&1

For a daily backup at 10.08pm :

8 22 * * * script/backup_mail.sh >/dev/null 2>&1

For a backup every 5th and 20th day of each month, at 1.22am :

22 1 5,20 * * script/backup_mail.sh >/dev/null 2>&1

For a monthly backup, every 10th day of each month, at 2.43am :

43 2 10 * * script/backup_mail.sh >/dev/null 2>&1

3 Installation and Test

Upload send_mail.pl, backup_mail.sh and my_crontab on your web server, in the script/ directory.

To check that everything is OK, run your script manually, after making it executable :

$ chmod u+x script/backup_mail.sh script/send_mail.pl
$ script/backup_mail.sh

Check for errors. If there are none, you should have a tar.gz archive in backup/ and receive a mail with a tar.gz attachment.

4 Register your Cron job

Register your Cron job using this command :

$ crontab script/my_crontab

Check your Cron job :

$ crontab -l
40 20 7,22 * * script/backup_mail.sh >/dev/null 2>&1

This means a backup will be performed on days 7 and 22 of each month, at 8.40 pm.

Clean the file since we don't need it anymore :

$ rm script/my_crontab

Conclusion

Be careful of the size of your backup, since mail attachments are limited to 10 Mo by many mail providers, and base64 file encoding during mail transfer increases size by about 30%. Limit your backups to 6 Mo, or create separate cron jobs for different parts of your web site, using several backup_mail.sh scripts (backup_mail1.sh, backup_mail2.sh,...).