View Single Post
Old 10-24-2007, 11:37 AM  
Juicy D. Links
So Fucking Banned
 
Industry Role:
Join Date: Apr 2001
Location: N.Y. -Long Island --
Posts: 122,992
Quote:
Originally Posted by SuckOnThis View Post
Here Juicy, this works fine. You can even have it email you the dump file if you want or just have it saved on the server.



#!/bin/sh

# List all of the MySQL databases that you want to backup in here,
# each seperated by a space
databases="name of database"
# Directory where you want the backup files to be placed
backupdir=/path/to/directory

# MySQL dump command, use the full path name here
mysqldumpcmd=/usr/bin/mysqldump

# MySQL Username and password
userpassword=" --user=username --password=your password"

# MySQL dump options
dumpoptions=" --quick --add-drop-table --add-locks --extended-insert --lock-tables"

# Unix Commands
gzip=/bin/gzip
uuencode=/usr/bin/uuencode
mail=/usr/sbin/sendmail

# Send Backup? Would you like the backup emailed to you?
# Set to "y" if you do
sendbackup="n"
subject="Your MySQL Backup"
mailto="[email protected]"

# Create our backup directory if not already there
mkdir -p ${backupdir}
if [ ! -d ${backupdir} ]
then
echo "Not a directory: ${backupdir}"
exit 1
fi

# Dump all of our databases
echo "Dumping MySQL Database"
for database in $databases
do
$mysqldumpcmd $userpassword $dumpoptions $database > ${backupdir}/${database}.dump
done

# Compress all of our backup files
echo "Compressing Dump File"
for database in $databases
do
rm -f ${backupdir}/${database}.dump.gz
$gzip ${backupdir}/${database}.dump
done

# Send the backups via email
if [ $sendbackup = "y" ]
then
for database in $databases
do
$uuencode ${backupdir}/${database}.dump.gz > ${backupdir}/${database}.dump.gz.uu
$mail -s "$subject : $database" $mailto < ${backupdir}/${database}.dump.gz.uu
done
fi


# And we're done
ls -l ${backupdir}
echo "Dump Successful and Complete!"
exit
thats niceeee save as a .sh file and execute via SSH right?
Juicy D. Links is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote