Taking Backup of your Website and WordPress Blog

Recently we updated viralpatel.net and moved to WordPress 2.8.4. The process of upgrading the wordpress went smooth. The wordpress installation you are running your website on must be updated regularly to avoid any kind of security threats in older versions of wordpress.

But while you play with your stable website code, it is always advisable to take backup of your website. The web hosting companies often take backup of the website hosted on their servers, but it is good to keep the backup locally.

Let us see different ways of taking Backup of a website.

Taking Code Backup of Website

A webmaster should often take the code backup of website to avoid any accidental loss of code. Also before every major/minor update in website, the backup of the code should be kept at a safe place. Following are few simple methods of taking website dumps or backup of code.

Full Backup using cPanel

cPanel provides wide variety of useful features to take backups of websites. One of such feature is Backup Wizard.

Goto cPanel -> Files -> Backup Wizard

You can take backup of the code, database, email filter configuration etc using this wizard.

Backup using FTP

FTP can be used to take backup of your website code. Lot of FTP clients are available which can be used to connect to a website using FTP and take the backup. My favorites are FileZilla and FireFTP (FireFTP is the popular Firefox extension).

Database Backup using PHPMyAdmin

PHPMyAdmin is a great MySQL frontend client which is already installed with cPanel. PHPMyAdmin can be used to take database backups directly.

Select PHPMyAdmin from your cPanel and select all the tables that you need to take backup of. Then click on Export and save the exported file in your machine. Database backup should be taken before any of the major updates in the website.

Automatic WordPress Database Backup using plugin


If you are using WordPress as your website CMS/Blogging software, you may want to take advantage of WP-DBManager, a cool wordpress plugin that take cares of the database backup.
WP-DBManager provides a number of options including optimize database, repair database, backup database, restore database, delete backup database , drop/empty tables and run selected queries. It also supports automatic scheduling of backing up and optimizing of database.

Automatic Database Backup using Cron Job

Cron Jobs are great way of scheduling daily task in your Webhosting space which can be configured to run at particular interval of time. You may want to schedule a Cron Job which automatically takes database backup on daily basis.

Here is a DB backup script that can be used for daily automatic DB backups. This script can backup multiple DBs at the same time. The script below is set to backup 2 DBs. If you want to backup more just copy and paste the bottom section and change info to match that DB. If you just want to backup just 1 DB then delete the second section of the bottom section of the script.The functions of the script are commented in the script.
Here are the steps to configure the automatic backup.

  1. Create a folder on the root of your web space called backups (don’t place this in the public_html directory. It belongs just about that in the directory structure)
  2. Create a folder named database_backups in the backups folder you just created.
  3. create a folder named the same as your DB in the database_backups folder you just created.
  4. Replace all of the text in the script enclosed in ” ” with your specific info.
  5. Save the db_dump script and place in the backups folder you created.
  6. CHMOD (permission) all files and folders in the backup directory to 700 including the backup directory
  7. Creat a CRON job in cPanel to execute this script. Go to the CRON tab in cPanel and click on advanced. Place this text in the command line replacing (“accountname”) /home/”accountname”/backups/db_dump.txt
  8. Change the CRON time to run at your desired time and press commit changes
#==============================================
#Save the script below as db_dump.txt
#==============================================


#!/bin/bash

# Script Created by Fernis
# Last edited 8/25/07 by Fernis

# Script Function:
# This bash script backups up the "DBname" and "DBname" db everyday at 4am with a file name time stamp and tar.gz zips the file.
# The "DBname" db will be saved in /backups/database_backups/"DBname"/
# The "DBname" db will be stored in /backups/database_backups/"DBname"/
# Db backups older than 30 days will be deleted.

#[Changes Directory]
cd /home/"accountname"/backups/

#[Old DB Deletion Script]
find /home/"accountname"/backups/database_backups -name "*.tar.gz" -mtime +30 -exec rm -f {} \;

#[Stamps the file name with a date]
TIMESTAMP=`date +%m-%d-%y-%H%M`


#[DB Backup Scripts]

# "DBname"
HOST=localhost
DBNAME="DBname"
USER="DBusername"
PASSWORD="DBpassword"
DUMP_PATH=/home/"accountname"/backups/database_backups/"DBname"
mysqldump --opt -c -e -Q -h$HOST -u$USER -p$PASSWORD $DBNAME > $DBNAME.sql
tar czpf $DUMP_PATH/$DBNAME.$TIMESTAMP.tar.gz $DBNAME.sql
rm -f $DBNAME.sql

# "DBname"
HOST=localhost
DBNAME="DBname"
USER="DBusername"
PASSWORD="DBpassword"
DUMP_PATH=/home/"accountname"/backups/database_backups/"DBname"
mysqldump --opt -c -e -Q -h$HOST -u$USER -p$PASSWORD $DBNAME > $DBNAME.sql
tar czpf $DUMP_PATH/$DBNAME.$TIMESTAMP.tar.gz $DBNAME.sql
rm -f $DBNAME.sql

#=======================================
#END OF BACKUP SCRIPT
#=======================================

View Comments

Share
Published by
Viral Patel
Tags: security website backup wordpress wordpress tips

Recent Posts

  • Java

Java URL Encoder/Decoder Example

Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…

5 years ago
  • General

How to Show Multiple Examples in OpenAPI Spec

Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…

5 years ago
  • General

How to Run Local WordPress using Docker

Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…

5 years ago
  • Java

Create and Validate JWT Token in Java using JJWT

1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…

5 years ago
  • Spring Boot

Spring Boot GraphQL Subscription Realtime API

GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…

5 years ago
  • Spring Boot

Spring Boot DynamoDB Integration Test using Testcontainers

1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…

5 years ago