Archive for October, 2006

MySQL Backup Script: Cron Hook

Tuesday, October 17th, 2006

Now let’s take that simple script below and automate it via cron.

To create a crontab:
type crontab -e then type in

MAILTO="yourmail@domain.com"
0 0 1,7,14,28 * * ~/scripts/mysqlbackup

then hit CTRL O to save then CTRL X to exit the editor

What does it mean? cron will run the mysqlbackup script on midnight every seven days of every month. If any error occurs then you’ll receive an email. If you want it to go to a log file just replace the above where appropriate with the code below:

0 0 1,7,14,28 * * ~/scripts/mysqlbackup > ~/logs/cron/cron.log

For a cron primer please refer to this site

MySQL Backup Script

Sunday, October 15th, 2006

I’ve switch to a new hosting company Dreamhost. I highly recommend them and if you need tons of savings google “dreamhost promo code” to get up to $97.00 bucks off your first year or two year subscription fee. My top hosting company choices were my previous hosting company for ai MediaTemple and Dreamhost. I choose Dreamhost because of the kick ass promo codes available from them and just the vast amount of options they provide. Initially, I was worried about the downtime they were having in the past months, but I also learned that MediaTemple collocates to the same building as some other major hosting companies so it just wasn’t Dreamhost with downtime. But as I continued to read on their blog, they are proactive at maintenance, upgrading data centers, so on and so on. I was quite satistfied with the hosting options they provided with the continual addition of bandwidth and storage on a weekly basis like what gmail does to storage however the blog probably helped me make the final decision to go with them. Anyway, I’ll write a more indepth post about them later. One of the options they provide is shell access (greeaaaat!) and from the indepth documentation they have online, here is a simple mysql backup script based on their script.


#! /bin/bash
cd ~/backups/mysql
dsuffix=$(date +%m%d%y)
tsuffix=$(date +%T)
mysqldump --opt -u username -ppassword -h sqlhost database > database_backup.$dsuffix.$tsuffix.sql
cat “database_backup.$dsuffix.$tsuffix.sql” | mail youremail@yourdoman.com

Make sure to replace the bolded text with your info. Also that’s not a mistake at -ppassword. If there is a space the script with prompt you for a password it’s completely up to you.