peech Therapy, Apraxia Articulation Word FlashCards

Speech Therapy, Apraxia Articulation Word FlashCards


Contact: kidsappbaba@gmail.com or Call : +1-980-APRAXIA

Joomla automated backup to Cloud service

Well.. what's the use of the backup if you can't have it when you need it the most. I learned it the hard way. I had joomla website which is backup using Akeeba. Being on the free version, had to settle for cron job that triggers the backup. 

Following is the php snippet that trigger Akeeba backup profile.

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,
SITEURL.'/index.php?option=com_akeeba&view=backup&key='.
SECRETKEY.'&profile='.PROFILE);
curl_setopt($curl_handle,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($curl_handle,CURLOPT_MAXREDIRS,10000); 
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);


So far good. But to be real useful your backup needs to somewhere else. And what better than free cloud service like Dropbox or Google drive. Akeeba professional has out the box integration with Dropbox. For google Drive, you can get it done by following below steps

1. Firs you Need to create a Google Drive service account. Here is nice post that has detailed steps about it 
2. Get the latest google drive client API.
3. Use cp2goole that has helper methods to connect to Google drive
4. As I was on PHP 5.2 has to hack two things
  •   to get around finfo to get MIME type, use the system command//$fi = new finfo( FILEINFO_MIME ); //$mimeType = explode( ';', $fi->buffer(file_get_contents($path)));
    $mime = exec('file -b --mime-type ' . $path);
  •  Google_P12Signer.php , use the hack  
  • 5. then write script that is specific to your needs
    $dir = "backupsDir";
    $dh  = opendir($dir);
    $strToSreach = "NameOfThebackpFile".date("Ymd");
    printf($strToSreach);
    $nameOfFile = "";

    //Search the file
    while (false !== ($filename = readdir($dh))) {
       
      if( substr($filename,-4) == ".sql" && substr($filename,0,15) == $strToSreach ) {
            printf("Found the file: ".$filename);
            $nameOfFile = $filename;
        }
    }

    $path  = $dir."/".$nameOfFile;

    printf("zipping the file: ".$nameOfFile ."
    ");

    exec('gzip  ' . $path);

    $path  = $dir."/".$nameOfFile.".gz";


    printf( "Uploading %s to Google Drive\n", $path ."
    ");

    $service = new DriveServiceHelper( CLIENT_ID, SERVICE_ACCOUNT_NAME, KEY_PATH );
    And with this, if you run this script, your backup should get triggered, it should create a joomla backup with SQL file, it should get zipped and sent to your google drive and your should get an email that says Backup has been shared with your email account !




PMP Preparation

I found below simulator very useful.





First RESTful Webservice

To create RESTful webservice using plain JDK, tomcat and Jersey (JAX-RS sample implementation)

Pre Requisite:
  1. JDK
  2. Tomcat ( any other servlet container)
  3. Jersey - Its sample JAX-RS implementation. It uses servlet controller that handle REST URLS.
Steps :
1. Create eclipse project with following structure
WEB-INF
--classes
--lib
--web.xml

2. Download latest Jersey jars from http://download.java.net/maven/2/com/sun/jersey/jersey-archive/ and extract it under lib folder.

3. Create following java class under src and make sure to set output folder in eclipse to WEB-INF/classes.

package com.rahul.ws;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("helloworld")
public class HelloWorldResource {
    @GET
    @Produces("text/plain")
    public String getMessage() {
        return "This is sample REST service";
    }
}

4. Add entry into web.xml for Jersey controller


    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
   
        RestfulContainer
        com.sun.jersey.spi.container.servlet.ServletContainer
       
            com.sun.jersey.config.property.packages
            com.rahul.ws
       

        1
   

   
        RestfulContainer
        /resources/*
   


5. Create war file using "%JAVA_HOME%\bin\jar" cvf restful.war WEB-INF

6. Deploy this war under tomcat and access the service using
    http://localhost:9090/restful/resources/helloworld
7. That's it !!