Put your tips and tricks online - Share your knowledge! Login | Register
 
 
  Search     Advanced search
 

Home | Ask Question | Add tip | My tips | Recent tips & tricks | Suggest a category | FAQ | Forums

 
 
 
 Category : Home > Databases > MySQL > Backup & Recovery     

Backup script for MySQL


#!/bin/bash
#
# This script will run in a loop for every database on the server and
# create a backup file per db. DUMPOPTIONS currently works with MySQL 4.0.24
# change it if you are using a different version
#
# Customize the variables below to adjust this script for your environment
# This should also work in ksh (Korn Shell)
#
PSSWD="mypassword"
BDIR="/backup/dir/"
MYSQL="/usr/local/mysql/bin/mysql"
DBDUMP="/usr/local/mysql/bin/mysqldump"
DUMPOPTIONS="--add-drop-table --add-locks --complete-insert --disable-keys --all
--extended-insert --flush-logs --lock-tables --quick --quote-names --password=${PSSWD}"
COMPRESS="/bin/gzip -f"
TODAY=`date +'%d%m%Y'`

for DB in `echo 'show databases' | ${MYSQL} -p${PSSWD} --column-names=false` ; do

        DUMPFILE="${BDIR}${DB}_${TODAY}.sql"
        ERRORMSG="ERROR: Backup of ${DB} failed"

        echo "Backing up ${DB} ..."
        ${DBDUMP} ${DUMPOPTIONS} ${DB} > ${DUMPFILE}
        if [ $? -eq 0 ] ; then
                ${COMPRESS} ${DUMPFILE} &
        else
                echo ${ERRORMSG}
        fi
        echo ""
        echo ""

done






  Options
 
   del.icio.us  |  newsvine  |  digg  |  furl  |  google  |  yahoo  |  Ma.gnolia  |  vigillar  |  reddit  |  technorati  |  icerocket  |  pubsub

     (Average: 4.71 / Votes: 14)   Rate this tip:    

Start discussion or add comment to this tip

  Details
Tip reference : #135
views : 2531
Added on : 10/28/06
Submited by : h8dk97
 
Send a message Send a message Printer friendly output Printer friendly output
Display this member's tips Display this member's tips (203)
 
 
Next >>
 Most viewed tips 
  Databases > Oracle > Security : How to unlock Oracle user account  
  Databases > Oracle > Performance Tuning : How to enable trace in Oracle  
  Operating Systems > Unix : How to kill Unix user session  
  Databases > Oracle : Kill user session  
   
  All categories
Databases | Programming | Hardware | Operating Systems | Networking | Internet | ERP / CRM | Games & Multimedia | Graphics & Design | Miscellaneous | Mobile Phones / Tablets | Office Software
 
 

Home |  FAQ |  Terms of Use |  Privacy Policy

© 2005 tiplib.com