The script to backup database file and

#! /bin/sh

TMP="/tmp/"

#Format the date in YEAR-MO-DY format
TODAY=`date +%d%b%Y`




# Set the web directory backup name to the following
WEB_FILENAME="MCI"$TODAY"web.tar.gz"

# Set database backup name to the following
DB_FILENAME="MCI"$TODAY"db.tar.gz"

# this tars up my web directory into web.tar.gz tarball.
/bin/tar -czf $TMP$WEB_FILENAME /var/www/html/mci

# Move the web back to the backup directory
/bin/mv $TMP$WEB_FILENAME /tmp

# Remove web backup file from temp director
#rm $TMP$WEB_FILENAME

# this tars up my database directory into $TODAY-db.tar.gz tarball. note that there is no space between -p and PASSWORD

mysqldump -u root -pPASSWORD -B WP_DB | gzip > $TMP$DB_FILENAME

# Move the backup database to the backup directory
/bin/mv $TMP$DB_FILENAME /tmp

 

Save this script as /var/scripts/backup_LAMP.sh

 

use crontab -e to schedule this script:

 

0 0 * * 1,4 /var/scripts/backup_LAMP.sh