Restore Backup API

Overview

If you wish to automate the Restoration of Backup using a different software, you can do that in Softaculous as there is an API Class which enables us to do so.

API Class

You can find the API Class in your Softaculous folder e.g. in cPanel its located here :

/usr/local/cpanel/whostmgr/docroot/cgi/softaculous/enduser/sdk.php

OR
You can find it here and place it into above mentioned path:
File:Softaculous Development Kit.zip

Understanding the API

The API is a simple class which will pass the data to Softaculous to restore a backup. Here is an example to restore a backup :

<?php
@set_time_limit(100);

include_once('sdk.php');

$new = new Softaculous_API();
$new->login = 'https://username:password@domain.com:2083/frontend/x3/softaculous/index.live.php';

// Default is serialize if nothing is specified
$new->format = 'serialize'; // There are three kind of formats available. [serialize][json][xml]. 

$data['restore_dir'] = 1; // Restore Directory
$data['restore_db'] = 1; // Restore Database
$data['restore_datadir'] = 0; // Restore Data Directory
$data['restore_wwwdir'] = 0; // Restore WWW Directory

$res = $new->restore('wp.26_60832.2012-07-26_10-13-33.zip', $data); // Restore API Call

$res = unserialize($res); // Get into Array
if(!empty($res['done'])){ // if $res['done'] == 1, restore was completed successfully
	echo 'Restored';
}else{
	echo 'Restoration Failed';
	print_r($res['error']); // Print the error
}
?>

As you may see this will Restore the wp.26_60832.2012-07-26_10-13-33.zip Backup. 

Lets go through the Code :

Initializing and Authentication

$new = new Softaculous_API();
$new->login = 'https://username:password@domain.com:2083/frontend/x3/softaculous/index.live.php';

This will load the Class in $new and we are setting the LOGIN URL as without authentication you will not be able to access Softaculous. The code here is an example to Restore Backup in cPanel. cPanel allows User Authentication via the URL itself and many other panels also.

'https://username:password@domain.com:2083

If your panel has some different method, you must first implement that code and then proceed.

Dont send emails

If you want no emails to be sent by Softaculous on the installation of a script please pass the &noemail=1& in the login url. e.g :

$new->login = 'http://user:password@domain.com:2082/frontend/x3/softaculous/index.live.php?&noemail=1&';

Result Format

Result format can be in three types: Serialize, XML & JSON. Here we are taking example of serialize

// Default is serialize if nothing is specified
$new->format = 'serialize'; // There are three kind of formats available. [serialize][json][xml].

Data Fields

Softaculous will expect you to submit the data fields as it shows during the installation of Scripts. Now most scripts have common fields like restore_dir and restore_db and stuff like that. The possible values these can be 0 and 1.

$data['restore_dir'] = 1; // Restore Directory
$data['restore_db'] = 1; // Restore Database
$data['restore_datadir'] = 0; // Restore Data Directory
$data['restore_wwwdir'] = 0; // Restore WWW Directory
$res = $new->restore('wp.26_60832.2012-07-26_10-13-33.zip', $data);

The above code is just setting to Restore Directory, Database, Data Directory & WWW Directory
The line $res = $new->restore(‘wp.26_60832.2012-07-26_10-13-33.zip’, $data); will start the restoration process and $res will have the result that is obtained.

List Backups

By following code you can get the list of backups

$backups = $new->list_backups();

Return Values

If the response is in the serialize format we can unserialize it and get the output in array.

$res = unserialize($res);
if(!empty($res['done'])){
	echo 'Restored';
}else{
	echo 'Restoration Failed<br/>';
	print_r($res['error']);
}

On a successful restore, $res[‘done’] will have the value 1 
On error, array $res[‘error’] is returned with the error details.

Support

You can always ask us if you have any queries. The support department can be accessed from here : https://www.softaculous.net/support/

Was this helpful to you?