Posts tagged "blah"

How to backup your MySql database to Dropbox using CodeIgniter PHP Framework

Last week I had a big problem with the System I have maintain for a couple of months now. Basically the system works like a storage of reports, so it uses Mysql Database to store and retrieve its data. The system also has this emailing functionality which sends a bunch of emails to an invited persons for its campaign every day with at least a couple of hundred emails sent. Then all of the sudden the system went offline and in the following hour I received an email from my hosting company stating that my hosting account was cancelled/terminated because I was violating their rules spam, bread and egg blah blah blah.

So basically what I would want in that very moment is to move the system to a new hosting or temporary live host so that we can still use the system. BUT! the problem then was I unable to access the host files and databases because my account was suspended, so I need to create support ticket to the hosting company requesting a temporary access to my files for backup. It took me almost 4 days to re-up the system into a new host from the backup files and data I grabbed from my hosting company from a long ticketing system wait.  WHAT I DIDN’T AND SHOULD HAVE DONE in the first place as a system developer was to create a functionality for the system to create a backup copy of the files and its database in a separate location.

Just recently I added “The backup functionality” for the system. A free storage from Dropbox and Brilliant API Library for PHP CodeIgniter solves my future problem. This library has this sample Controller implementing its uses.

To use this library you need to create a dropbox application here and get the ‘App Key’ and ‘App Secret’. After you create you archiving routine of your files and database, you can then proceed to the API use. The library’s sample controller has all you need to run your saving of your files.

The request_dropbox() function should be the first function to be executed, you need to provide you Dropbox application app key and app secret. This function will initiate the the hand-shake between the user’s dropbox account and your dropbox application. Your dropbox application will ask the user to allow the application to control (create folder, save files, etc) the users dropbox account.

Here’s the snippet of request_dropbox function

$params [ 'key' ] = 'YOUR DROPBOX CONSUMER KEY' ;
$params [ 'secret' ] = 'YOUR DROPBOX CONSUMER SECRET' ;

$this -> load -> library ( 'dropbox' , $params ) ;
$data = $this -> dropbox -> get_request_token ( site_url ( "example/access_dropbox" ) ) ;
$this -> session -> set_userdata ( 'token_secret' , $data [ 'token_secret' ] ) ;
redirect ( $data [ 'redirect' ] ) ;

Here’s the test function

public function test_dropbox ( ) {
$params [ 'key' ] = 'YOUR DROPBOX CONSUMER KEY' ;
$params [ 'secret' ] = 'YOUR DROPBOX CONSUMER SECRET' ;
$params [ 'access' ] = array ( 'oauth_token' => urlencode ( $this -> session -> userdata ( 'oauth_token' ) ) ,
'oauth_token_secret' => urlencode ( $this -> session -> userdata ( 'oauth_token_secret' ) ) ) ;

$this -> load -> library ( 'dropbox' , $
$dbobj = $this -> dropbox -> account ( ) ;
print_r ( $dbobj ) ;
}

to see more if its functionality you can freely read its Class here

I maybe not clear enough explaining how to implement this library BUT THIS WILL: THE READ ME . I hope you find this article helpful and prevent what I went through.

Leave a comment below if you need more clarification. I’d be glad to help.

Be the first to comment - What do you think?
Posted by Mark Anthony Sabandal - June 15, 2012 at 9:17 pm

Categories: PHP Tags: , , , , , , , , , , , , , , ,