View Single Post
Old 07-16-2007, 07:13 AM  
ServerGenius
Confirmed User
 
Join Date: Feb 2002
Location: Amsterdam
Posts: 9,377
Quick and easy mysql backup script

Code:
#!/bin/bash

#
# Mysql Backup Script
# Hans Waasdorp [email protected]
#

TODAY=`/bin/date +%d-%m-%y`

BACKUP_MYSQL=1

DEST_DIR="/path/to/backup/dir"

DESTINATION_DIR="$DEST_DIR/$TODAY"
KEEP_DAYS=7

# edit below PASSWD="password" and USER="username" to your mysql username and password 

if [ $BACKUP_MYSQL -eq 1 ]; then
  PASSWD="password"
  USER="username"
  DATABASES=`mysql -BN -u $USER --password=$PASSWD -e 'SHOW DATABASES;'`

  if [ -x /usr/bin/mysqldump ]; then
    for db in $DATABASES; do
      mkdir -p $DESTINATION_DIR
      cd $DESTINATION_DIR
      /usr/bin/mysqldump --opt -u $USER --password=$PASSWD $db | gzip - | cat - > mysql.$db.dump.gz
    done
  fi
fi

/usr/bin/find $DEST_DIR/ -type d -mtime +$KEEP_DAYS | xargs rm -rf 2>&1 > /dev/null
__________________
| http://www.sinnerscash.com/ | ICQ: 370820 | Skype: SinnersCash | AdultWhosWho |
ServerGenius is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote