- 21stsoft.com – Web Development, Software Development, SEO Firm - http://www.21stsoft.com -
WordPress Tutorial – WordPress Backups
Posted By Michael Cordova On April 4, 2009 @ 3:17 pm In | No Comments
Before you add any WordPress content you MUST ensure that a backup and restore process is in place. The importance of this cannot be over-emphasized. Every hour that you spend adding content to your website can be erased if the database crashes – databases do crash, and this is fair warning.
Before adding content make sure that your website administrator has a backup scenario in place and that regular backups have been verified.
MANUAL BACKUPS
To perform manual full or partial MySql database and file backups you can go into the website cPanel and click the Backup Wizard in the Files section then select the backup options you want. A full backup backs up everything about the site including email configurations and all site files. Partial backups can include one or all of the following:
Home directory
MySql databases
Email Forwarders and Filters
When these backups are performed they will be placed in the root folder of the website:
/
To extract (and possibly restore) only the WordPress database file you need to open the tar file that is backed up and extract the .sql file in the .\mysql\ folder. A typical file is named domainsp5_sswp01.sql.
AUTOMATIC SITE BACKUPS
This is our normal automatic backup process:
Backup WordPress MySql Database – to automatically backup the WordPress MySQL database (and all other website MySQL databases) at BlueHost.com we run a WordPress backup script [2] named backupDatabases.sh that resides in the root folder of the website. You must set the permissions of the Owner user for this file to allow executes. This requires a security setting of 744. This backup script is usually run daily unless a lot of content is being added in which case we’ll run it 4 times a day. To run the script automatically you need to create a CRON job for it. CRON jobs are explained below. The backups it creates are located in this folder of the website:
/backup/mysql/
CRON JOBS
A CRON job is simply a scheduled task in Linux or any Unix-based machine.
You can run CRON jobs from your cPanel (Advanced – last section at the bottom of the page) to execute the first set of backups described above. You can change the frequency of these backups by clicking the CRON Jobs icon.
Don’t forget to enter your email address when you define a CRON job so you can receive notifications when it runs.
The backup script described in this page allows you to create automatic backups of your MySql database when you use it in a CRON job.
All of the content below the line under this sentence with all ### should be copied to a file named backupDatabases.sh. Once this is done you need to do the following to set up your automatic database backups:
Note that the files are placed into this folder of your website:
/backup/mysql/
##################################
#!/usr/bin/env bash
#======================================================
#
# FILE: backup_db.sh
# USAGE: ./backup_db.sh password
# DESCRIPTION: Backup all my databases one by one
# VERSION: 1.2-STABLE
# CREATED: 11/28/08 11:42:00 MST
# REVISION: —
#======================================================
#——-Configuration Settings——-#
user=”CPUsername”; #A Database User with Privileges on all dbs
pass=”CPPassword”; #Said user’s password !!
#—–Don’t Edit Below This Line—–#
if [[ `uname` = "Linux" ]];
then
expath=”/usr/bin”;
mystat=”stat -c %Y”;
fi;
if [[ `uname` = "FreeBSD" ]];
then
expath=”/usr/local/bin”;
mystat=”stat -f %B”;
fi;
ts=`date +%s`; #For the file timestamps
d=`date +%Y%m%d-%H%M`; # For other uses
month=2592000; #One month
#month=178200; #2 days For testing
dir=”$HOME/backups/”; # Directory to store the backups
if [[ ! -d $dir ]]; #Make sure the dir exists and create if not.
then
mkdir -p $dir;
fi;
# First let’s prune the backup dir of files over a month old
cd $dir;
for l in `ls $dir`;
# Works CentOS and Ubuntu…
do mt=`$mystat $l`;
result=$(($ts-$mt));
#echo $result;
if ((“$result” >= “$month”));
then
echo “Deleting: $l”;
rm -f $l;
fi;
done;
# Let’s do this
for i in `echo “show databases” > $expath/mysql -u$user -p$pass > grep -v Database`;
do var=${i}${d};
$expath/mysqldump -R -p$pass -u$user $i > $var.sql && echo $i backed up on $d;
done;
#————————
Article printed from 21stsoft.com – Web Development, Software Development, SEO Firm: http://www.21stsoft.com
URL to article: http://www.21stsoft.com/wordpress-tutorial-wordpress-backups/
URLs in this post:
[1] Home: http://www.21stsoft.com
[2] WordPress backup script: #wordpress-mysql-database-backup-script
Click here to print.
Copyright © 2009 21st Century Technologies, Inc.. All rights reserved.