Backup Site and Database in Codeigniter

In the world of web it is important to take backup of our site and database frequently. We don’t know when we’d come accross unexpected error which causes our site stop working. Here I have developed an application in Codeigniter which will help you to take backup as per your wish wnenever you want to take backup. While most web hosting company do a daily backup of a customer’s database and site, relying on them to make backups and provide them at no cost is risky also.

Never take chances when your website is on the line. Make frequent backups !

You can see the comments inside the Controller and I think it’s easy to understand. If you do not want it to use with Codeigniter you could also use it in simple PHP application and for that you just need to understand the logic carefully so that you can use the code logic anywhere.

If you have any query please feel free to send a query.

First thing is we need to create database tables

The below backup table holds the information for backup

 

The below session table holds session information for each client

 

Create assets directory, where css, images and js files will reside, at the root level i.e. parallel to application directory as shown into the picture.

Codeigniter site and database backup

Download and put the below images into assets/images directory

codeigniter_backup_images

Create backups/databases and backups/sites directory which will hold the backups for databases and sites correspondingly as shown below picture

Codeigniter site and database backup

Configure database settings at location application/config/database.php

 

Modify the config.php file at location application/config/config.php

I am not using index.php file in URL so you can go through tutorial how to remove index.php from URL in Codeigniter

 

Modify the autoload.php file at location application/config/autoload.php

 

View

This view gives the presentation how the inputs will be available to the end users.

 

Model

This model is responsible for saving backup to databse and deleting backup from database.

 

Controller

This controller does everything for you like taking backup, downloading backup, deleting backup, saving backup to database, saving backup to disk space etc.

 

Now run the application. Make sure that your web server and MySQL server are running.

Home Page

Codeigniter site and database backup

When inputs are not selected

Codeigniter site and database backup

When inputs are selected and clicked on ‘Get Backup’ button

Codeigniter site and database backup

The entry saved into the backups/databases directory

Codeigniter site and database backup

The entry saved into the database

Codeigniter site and database backup

When you get backup you are given two options – either you can download or delete the backup.

When you click on the delete link to delete the backup you are given a confirmation link whether you really want to delete the backup

Codeigniter site and database backup

When backup deleted from the backups/databases directory

Codeigniter site and database backup

When backup deleted from the database

Codeigniter site and database backup

Thanks for your reading. Please leave a comment if you any doubt or query.

Soumitra

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

3 thoughts on “Backup Site and Database in Codeigniter

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.