Support Forum Articles File Help Startup DB Tips Service DB Hijack This! Analyzer

 

MySQL DB backup - Automated shell script
Step 2: insert the contents (Bold means customize)

#!/bin/sh

# List all of the MySQL databases that you want to backup in here,
# each separated by a space
databases="DBNAME"
backupdir=/FULL/PATH
mysqldumpcmd=/usr/bin/mysqldump
userpassword=" --user=USER --password=PASS"

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

# Unix Commands
gzip=/bin/gzip

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

#get currentdate
today=`date +%w`

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

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

# And we're done
# This displays the data
ls -l ${backupdir}
# Sets permissions for our next step ;) FTP synchronization use
chown backup *.*
chgrp psacln *.*


Written By: Martin Krohn
Date: 7-30-04
Views: 12930
Printer Friendly

Article Index:
Page 3 -->