Backup Of Joomla, Drupal, EE, Wordpress, etc.

It doesn’t matter what you’re running as CMS, forum or blog. Most software solutions are based on an Apache2 Server and a mySQL database. But only a few people are aware of appropriate backup solutions.

I hope below script will help people, who are not yet familar with rootserver, and are used to reinstall their systems (guess why I do know this ). Below two scripts will help you on creating a backup for your mySQL database and creating a dump of your whole web presentation files.

Below script will do the necessary BACKUP for you:

#!/bin/bash
# BACKUP SCRIPT FOR ROOTSERVERS
#
# ASSUMPTIONS:
# data stored in a mysql database (dumping and taring DB)
# webfiles (taring all webfiles)
#
# save this script e.g. web_backup.sh
# don't forget to chmod 700 web_backup.sh
# execute script via ./web_backup.sh
#
#
# DO NOT STORE FILES IN WEB ROOT FOR SECURITY PURPOSES!
#
# THIS SCRIPT IS OPENSOURCE
#
# written by Jeannot Muller
#
# mailto:jeannot.muller@ramgad.com:
# http://www.ramgad.com
#
#
# Version 2.1 (23th March 2008)

# DATADECLARATION
HOSTNAME=localhost
DB_NAME='db_name'
DB_USER='db_user'
DB_PASSWORD='db_password'
BACKUP_PATH_DB='xxx'
BACKUP_PATH_WB='yyy'
BACKUP_NAME_DB='database'
BACKUP_NAME_WB='webroot'
WEB_ROOT_PATH='/var/www/'
FTP_DEST='backup999.onlinehome-server.info'
FTP_USER='ftp_user'
FTP_PWRD='ftp_pwrd'
FTP_PATH_DB='/db_backup/'
FTP_PATH_WB='/wb_backup/'

# BUILDING TIMESTAMP FOR ALL FILES
TIME_STAMP=`date +%m-%d-%Y-%Hh%M`

# DATA CLEANSING
# (delete all files older than 20 days)
find $BACKUP_PATH_DB -name "*.tar.gz" -mtime +20 -exec rm -f {} \;
find $BACKUP_PATH_WB -name "*.tar.gz" -mtime +20 -exec rm -f {} \;

# EXECUTING DUMP FROM MYSQL
cd $BACKUP_PATH_DB
mysqldump --opt -c -e -Q -h$HOSTNAME -u$DB_USER -p$DB_PASSWORD $DB_NAME > $BACKUP_NAME_DB.sql

# COMPRESSING: DUMP AND ADDING TIMESTAMP
tar czpf $BACKUP_PATH_DB/$BACKUP_NAME_DB.$TIME_STAMP.tar.gz $BACKUP_NAME_DB.sql

# MOVING TO WEB_ROOT
cd $WEB_ROOT_PATH

# COMPRESSING ALL WEBROOT FILES (and copy latest version)
tar czpf $BACKUP_PATH_WB/$BACKUP_NAME_WB.$TIME_STAMP.tar.gz *
cp $BACKUP_PATH_WB/$BACKUP_NAME_WB.$TIME_STAMP.tar.gz $BACKUP_PATH_WB/$BACKUP_NAME_WB.tar.gz

# BACKUP TO EXTERNAL SERVER
ftp -n $FTP_DEST <<SCRIPT
quote USER $FTP_USER
quote PASS $FTP_PWRD
binary
put $BACKUP_PATH_DB/$BACKUP_NAME_DB.$TIME_STAMP.tar.gz $FTP_PATH_DB/$BACKUP_NAME_DB.$TIME_STAMP.tar.gz
put $BACKUP_PATH_WB/$BACKUP_NAME_WB.$TIME_STAMP.tar.gz $FTP_PATH_WB/$BACKUP_NAME_WB.$TIME_STAMP.tar.gz
quit
SCRIPT
exit 0

Below script will do the necessary RESTORE for you:

#!/bin/bash

# RESTORE SCRIPT FOR ROOTSERVERS
#
# ASSUMPTIONS:
# correct Datadeclaration
#
# save this script e.g. web_restore.sh
# don't forget to chmod 700 web_restore.sh
# execute script via ./web_restore.sh
#
#
# DO NOT STORE FILES IN WEB ROOT FOR SECURITY PURPOSES!
#
# THIS SCRIPT IS OPENSOURCE
#
# written by Jeannot Muller
#
# mailto:jeannot.muller@ramgad.com
# http://www.ramgad.com
#
#
# Version 2.1 (23th March 2008)

# DATADECLARATION
HOSTNAME=localhost
DB_NAME='db_name'
DB_USER='db_user'
DB_PASSWORD='db_password'
BACKUP_PATH_DB='xxx'
BACKUP_PATH_WB='yyy'
BACKUP_NAME_DB='database'
BACKUP_NAME_WB='webroot'
WEB_ROOT_PATH='/var/www/'

# CLEANSING WEBROOT
cd $WEB_ROOT_PATH
rm -R *

# COPYING BACKUP INTO ROOT
cp $BACKUP_PATH_WB/$BACKUP_NAME_WB.tar.gz $WEB_ROOT_PATH

# DECOMPRESSING FILES
tar xfvz $WEB_ROOT_PATH/$BACKUP_NAME_WB.tar.gz

# DELETING SOURCE IN ROOT
rm $WEB_ROOT_PATH/$BACKUP_NAME_WB.tar.gz

# RESTORE DATABASE
mysql -h$HOSTNAME -u$DB_USER -p$DB_PASSWORD $DB_NAME < $BACKUP_PATH_DB/$BACKUP_NAME_DB.sql
  • Digg
  • del.icio.us
  • Google
  • MisterWong
  • Technorati
  • Mixx
  • Blogosphere News
Sphere: Related Content

Tags: , , , ,