A complete WordPress site backup is not always easy to perform when some of the folders to save are not in standard WordPress directories.
Here is a simple solution to achieve the task without any plugin.
I'm not a coder and all the lines below are the result of crawling over the net.
I've only adapted the code and changed some parameters for my needs.
Enable first SSH/ Shell access on your cpanel in order to be able to execute script.
If your SSH access is disabled, click on "Manage SSH access" to enable.
In order to identify your WordPress path, go to cpanel and click on "File Manager".
You will see your root path in front of the the Home icon (WordPress path = root path/public_html/).
Don't forget to create your backup path by FTP if it does'nt exist.
Copy/ paste the content of the following script in notepad++, replace text in red color with your own informations and save it to a unix script .sh file (Backup.sh for example).
Then, tranfer this file by FTP to your root directory.
#!/bin/sh
#
# Customize these variables. You have to create backup path by ftp if it doesn't exist
#
EMAIL=xxx.yyy@yahoo.com
WORDPRESS_PATH="/home/website/public_html"
BACKUP_PATH="/home/website/wp_backups/website-backup"
#
# valid path test - Exit if wrong path
#[ ! -d $WORDPRESS_PATH ] && echo "Not a valid directory : $WORDPRESS_PATH" && exit 1[ ! -f $WORDPRESS_PATH/wp-config.php ] && echo "Cannot find wordpress config file 'wp-config.php'" && exit 1[ ! -d $BACKUP_PATH ] && mkdir -p $BACKUP_PATH
#
# Script variables
#
NOW=`date +%Y-%m-%d_%Hh%Mm%S`
WP_PARENT=`dirname $WORDPRESS_PATH`
#Create Backup sub-directory with date and time
mkdir $BACKUP_PATH/Backup-$NOW
# Entire public_html directory backup and compression
cd $WP_PARENT
tar zcf $BACKUP_PATH/Backup-$NOW/Global-Backup-$NOW.tar.gz public_html
cd $OLDPWD
# read wordpress wp-config.php file to extract DB Name, Username, Password and use it in variables
WP_CONFIG="$WORDPRESS_PATH/wp-config.php"
PROPS=$(sed -e "/define('DB_(NAME|USER|PASSWORD|HOST)/!d"
-e "s/[^']*'DB_(NAME|USER|PASSWORD|HOST)'[^']*'([^']*)'.*$/DB_1='2';/g" ${WP_CONFIG}) && eval $PROPS;
#
# Database backup and compression
#
mysqldump -p$DB_PASSWORD -u$DB_USER $DB_NAME > $BACKUP_PATH/Backup-$NOW/backup_$DB_NAME-$NOW.sql
gzip -v $BACKUP_PATH/Backup-$NOW/backup_$DB_NAME-$NOW.sql
#send an email when finished !
echo "Backup completed" | /usr/bin/mail -s "Wordpress and Mysql backups completed " $EMAIL
Change the file permissions of Backup.sh to 700 in order to be able to execute it and to perform your WordPress site backup.
To schedule script execution, go to your cpanel and click on Cron jobs icon.
Here are the parameters to perform one backup by day at midnight.
Enter the execution command /bin/sh /root path/your script file name and press Add New Cron Job button to valid.
Wordpress site backup is done !
Complete wordpress site backup takes about 18 min (5.5 Go).
Don't forget to transfer the resulting files on your computer after backing up because most of host providers doesn't allow to keep backup files on their servers (you can automate this transfert with Syncbackfree, a free software that enable you to perform scheduled transferts and backups between ftp and your computer).
Great information! Thanks for sharing this information!
You're welcome, George !
Hi there, just became aware of your blog through Google, and found that it's truly informative. I am gonna watch out for brussels. I¡¯ll be grateful if you continue this in future. Numerous people will be benefited from your writing. Cheers!
Thanks a lot 🙂
This excellent post definitely has all of
the information and facts I wanted concerning this subject and
didn't know who to ask.