The script to backup database file and website file:
#! /bin/sh TMP="/tmp/" #Format the date in YEAR-MO-DY format TODAY=`date +%d%b%Y` # Set the Apache Configuration backup name to the following CFG_FILENAME="MCI"$TODAY"cfg.tar.gz # 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 the apache configuration files /bin/tar -czf $TMP$CFG_FILENAME /etc/httpd/conf* #Move the apache configuration file to the backup directory /bin/mv $TMP$CFG_FILENAME /tmp # 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