WordPress sites backup shell script

WordPress sites backup shell script

#! /bin/bash

## backup script for the wordpress site
## taking complete backup of website folder, database & apache configuration files
## itquery(at)gmail.com

TIMESTAMP=$(date +”%F”)
IPA=`hostname -I| awk ‘{print ($1)}’`
BACKUP_DIR=”/backup/BKP_$IPA/$TIMESTAMP”

#### Website folder path details ###
WWW=/opt/www

### MYSQL details ###
MYSQL_USER=”root”
MYSQL=/usr/bin/mysql
MYSQL_PASSWORD=”password”
MYSQLDUMP=/usr/bin/mysqldump

echo “Backup started `date`..”

mkdir -p “$BACKUP_DIR/mysql”

databases=`$MYSQL –user=$MYSQL_USER -p$MYSQL_PASSWORD -e “SHOW DATABASES;” | grep -Ev “(Database|information_schema|performance_schema)”`

for db in $databases; do
$MYSQLDUMP –force –opt –user=$MYSQL_USER -p$MYSQL_PASSWORD –databases $db | gzip > “$BACKUP_DIR/mysql/$db.gz”
done

mkdir -p “$BACKUP_DIR/conf.d”
cp -rvf /etc/httpd/conf.d/* $BACKUP_DIR/conf.d

ListFolder=`ls -1 $WWW`

for folder in $ListFolder; do
tar -zcvf $BACKUP_DIR/$folder.gz /opt/www/$folder

done

echo “Backup completed `date`..”

This entry was posted in Database, Shell script. Bookmark the permalink.

Leave a Reply