Backing Up and Emailing Home Directory and SQL Databases

Hello,

I run a web hosting company, and I'm wondering how I can use cPanel's Cron Jobs so that a copy of my entire home directory and a copy all of my MySQL databases can be compressed and emailed to me. I know nothing about Linux, Unix, or whatever that thing with the penguin is called. :slight_smile:

Anthony

Now here is a question, where did you install cPanel? :confused:
It has to be Linux/Unix. The thing with Penguin.. :rolleyes: That's Tux, de-facto Linux mascot

Here is a simple MySQL dump script, it'll rotate weekly:

#!/bin/bash
export week_day=`date +%u`
mkdir -p /some_path/mysql_backup/$week_day
for i in `echo "show tables" | mysql -u username -ppassword database|grep -v Tables_in_`;
do
  echo $i; mysqldump --add-drop-table --allow-keywords -q -a -c -u username -ppassword database $i > backup/$week_day/$i.sql
  rm -f backup/$week_day/$i.sql.gz
  gzip backup/$week_day/$i.sql
done

To set cron:

30 0 * * * /path_to_script/mysql_backup_script >/dev/null 2>&1

This will run your backup script at 12:30 AM, everyday.
As for mailing, I have a script somewhere, I'll have to dig it up.

-Nitin

I am a hosting reseller account, so it was automatically installed for me.

I did some Linux research online, and I found out how to compress the contents of my public_html directory. Now I just need to figure out how to send that file to my email and then delete the file off of the server.

Here's the command I used for compressing my public_html directory

date=`date -I` ; tar -zcf backup_$date.tgz ./public_html

Also, how does that SQL thing work, and how do I change the script to fit my needs?

Try this for mailing:

 uuencode backup.tar.gz | mailx -s "My backup" my@email.org 

HTH,
Nitin

Didn't get an email with this command

date=`date -I` ;  uuencode backup_$date.tar.gz | mailx -s "Your Daily Site Backup" *******@gmail.com

---------- Post updated at 03:09 PM ---------- Previous update was at 01:59 PM ----------

I finally got it with mutt and then I used the RM command to remove the file. I tested it and it works. Now I need to try out the MySQL backup.

Run the uuencode, see if you get any thing like this:

/usr/bin/uuencode
Try `uuencode --help' for more information.

Next try mailx the same way. You use 'mail' instead of mailx. I think. I'll have to test. If you get 'command not found' error, then either it's not installed or it's /usr/bin is not in your path. Do

echo $PATH

-Nitin

It worked with mutt, and I was able to finish the job by using the rm command to remove the file once it was sent to me via email. Now, how do you do the MySQL backup?

MySQL backup : Look at my first script