backupWordPress.sh 969 Bytes
#! /usr/local/bin/bash
BACKUPDIR=/backups
WORDPRESSDIR=/usr/local/www/apache24/data/wordpress

if [[ ! -d "$BACKUPDIR" ]]; then
	echo "Backup Directory: $BACKUPDIR not found, creating...."
	mkdir -p "$BACKUPDIR"
fi
source /root/database_config
if [[ "$db_name" = "" ]]; then
	echo "Configuration invalid, DB Name is not set. Exiting..."
	exit
elif [[ "$db_user" = "" ]]; then
	echo "Configuration invalid, DB User is not set. Exiting..."
	exit
elif [[ "$db_password" = "" ]]; then
	echo "Configuration invalid, DB Password is not set. Exiting..."
	exit
fi

cd "$BACKUPDIR"
echo "Starting backups..."
echo "Backing up WordPress Database..."
backupDate=$(date +"%Y%m%d")
/usr/local/bin/mysqldump -u"$db_user" -p"$db_password" "$db_name" --skip-add-locks --skip-lock-tables > "$db_name$backupDate".sql

echo "Done."
echo "Backing up WordPress Files..."
/usr/bin/tar czf wordpress"$backupDate".tar.gz "$WORDPRESSDIR"

echo "Done."
echo "Backups Completed. Exiting..."
exit