WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : One Stop Bash script to backup all you need on a LAMP server. MySQL, Apache configuration files, WWW content, crontabs and more
Categories : Scripts, Bash, Backup
Boaz Yahav
Date : May 12th 2011
Grade : 1 of 5 (graded 4 times)
Viewed : 4446
File : Backup.sh
Images : No Images for this code example.
Search : More code by Boaz Yahav
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This Bash script will automatically take care of backing up all your critical information so that in a disaster you can setup your site(s) on a new server. Obviously you will need to offload the backups to a different location from time to time.

This script takes care of :
* apache configuration files
* crontabs
* /home/WWW (or wherever you keep your content / code)
* /etc
* MySQL (All DBs)
* it will also Rotate the MySQL query log if you have it running for debugging / dev.


#!/bin/bash
#
echo ""
#Rotate the MySQL query log
echo '' > /usr/local/mysql/var/mysql_queries.log
#
MUSER=""
MPASS=""
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
BACKUPDIR="/var/backup"
GZIP="$(which gzip)"
NOW=$(date +"%d-%m-%Y")
TAR="$(which tar)"

[ ! -d $BACKUPDIR ] && mkdir -p $BACKUPDIR || /bin/rm -f $BACKUPDIR/*

echo ""
echo "apache configuration files are being backed up: "
$TAR -cjf $BACKUPDIR/apache_conf.tar.$NOW.bz2 /usr/local/apache/conf
#
echo ""
echo "crontabs are being backed up: "
$TAR -cjf $BACKUPDIR/crontabs.tar.$NOW.bz2 /var/spool/cron
#
echo ""
echo "/home/WWW is being backed up: "
$TAR -cjf $BACKUPDIR/home_WWW.$NOW.tar.bz2 /home/WWW
#
echo ""
echo "/etc is being backed up: "
$TAR -cjf $BACKUPDIR/etc.$NOW.tar.bz2 /etc
#
echo ""
echo ""
#
echo "mySQL backup script has been started."
echo "The following databases are being backed up: "
echo ""
echo "--------------------------------------------"
echo ""
#
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
echo $db
FILE=$BACKUPDIR/$db.$NOW.gz
$MYSQLDUMP -R -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done