Current File : //backup/mysqlrestore.php
<?php
// Filename.php username Filename
if($argc!==3)
{
	echo "could you please pass the parameters correctly.";
	exit();
}
if(!file_exists("/backup/".$argv[1]."/".$argv[2]))
{
	echo "File name does not exists in the given user backup folder";
	exit;
}
if(substr($argv[2], -3)!='zip')
{
	echo "Restore has accept only zip files";
	exit;
}
/* ///////////////////////////////////////////// Calculation start /////////////////////////////////// */
$path="/backup/".trim($argv[1])."/".trim($argv[2]);
$total_bk_size_in_kb=shell_exec("unzip -l $path | tail -1 | awk '{print $1}'");
$available_size_in_kb=shell_exec("df | awk '{print $4}' | head -2 | tail -1");
$overall_size_in_kb=shell_exec("df | awk '{print $2}' | head -2 | tail -1");
if($available_size_in_kb < $total_bk_size_in_kb )
{
	echo "Due to disk space exceeed, your restore does not working. kindly contact your administrator.";
	exit;
}
$remaining_kb=$available_size_in_kb - $total_bk_size_in_kb;
$remaining_percentage = $remaining_kb / $overall_size_in_kb * 100 ;
if($remaining_percentage < 5 )
{
	echo "Due to disk space exceeed, your restore not working. kindly contact your administrator.";
	exit;
}

/* ///////////////////////////////////////////// Calculation End /////////////////////////////////// */
require('/etc/sentora/panel/cnf/db.php');
include('/etc/sentora/panel/dryden/db/driver.class.php');
include('/etc/sentora/panel/dryden/debug/logger.class.php');
include('/etc/sentora/panel/dryden/runtime/dataobject.class.php');
include('/etc/sentora/panel/dryden/runtime/hook.class.php');
include('/etc/sentora/panel/dryden/sys/versions.class.php');
include('/etc/sentora/panel/dryden/ctrl/options.class.php');
include('/etc/sentora/panel/dryden/fs/director.class.php');
include('/etc/sentora/panel/dryden/fs/filehandler.class.php');
include('/etc/sentora/panel/inc/dbc.inc.php');
try 
{
    $zdbh = new db_driver("mysql:host=" . $host . ";dbname=" . $dbname . "", $user, $pass);
} catch (PDOException $e) {
exit();
}
$download=1;
if (isset($argv[1]) && $argv[1] != "") {
  
		$username=trim($argv[1]);
				$rows = $zdbh->prepare("
				SELECT * FROM x_accounts 
				LEFT JOIN x_profiles ON (x_accounts.ac_id_pk=x_profiles.ud_user_fk) 
				LEFT JOIN x_groups   ON (x_accounts.ac_group_fk=x_groups.ug_id_pk) 
				LEFT JOIN x_packages ON (x_accounts.ac_package_fk=x_packages.pk_id_pk) 
				LEFT JOIN x_quotas   ON (x_accounts.ac_package_fk=x_quotas.qt_package_fk) 
				WHERE x_accounts.ac_user_vc= :ac_user_vc
				");
				$rows->bindParam(':ac_user_vc', $username);
				$rows->execute();
	if ($rows->fetchColumn() != 0) {		
					$rows = $zdbh->prepare("
					SELECT * FROM x_accounts 
					LEFT JOIN x_profiles ON (x_accounts.ac_id_pk=x_profiles.ud_user_fk) 
					LEFT JOIN x_groups   ON (x_accounts.ac_group_fk=x_groups.ug_id_pk) 
					LEFT JOIN x_packages ON (x_accounts.ac_package_fk=x_packages.pk_id_pk) 
					LEFT JOIN x_quotas   ON (x_accounts.ac_package_fk=x_quotas.qt_package_fk) 
					WHERE x_accounts.ac_user_vc= :ac_user_vc
					");
					$rows->bindParam(':ac_user_vc', $username);
					$rows->execute();
					$dbvals = $rows->fetch();
					$userid=$dbvals['ac_id_pk'];		
					
			if ($backup = ExecuteRestore($userid, $username, $download,$argv[2])) {
			
			echo "Restore completed.";
			
			} else {
			
			//echo "<h2>Unauthorized Access!</h2>";
			echo "This File Not created by HRPanel. For security reason we have not allowed this files.";
			
			}
	}
	else
	{
	echo "Username does not exists.";
	exit();		
	}
}
function ExecuteRestore($userid, $username, $download = 0,$filename) {
	include('/etc/sentora/panel/cnf/db.php');
   echo "Restart started. \n";
	$dest_path="/var/sentora/hostdata/".$username."/";
	# $src_path="/var/sentora/hostdata/".$username."/";
	$src_path="/backup/".$username."/"; 
	echo $cmd="cd $src_path && unzip $filename &&  cd mysql/ 2>&1 ";
	echo "\n";
	$output=passthru($cmd,$return_val);
	 echo $cmd="cd $src_path && unzip $filename &&  cd mysql/ 2>&1 ";
	 $dbname=md5(sha1($username."SQL")).".sql";
	//echo "/var/sentora/hostdata/".$username."/mysql/".$dbname."\n";
	echo "\n";
	if(file_exists("/backup/".$username."/mysql/".$dbname))
	{
echo "Hai";
	$cmd="mysql -u $user -p$pass < /backup/$username/mysql/$dbname"; 
	$output=passthru($cmd,$return_val);
	$output=array();
	$return_val="";
	$output=passthru($cmd,$return_val);
	$cmd="rm -fr /backup/$username/mysql";
	exec($cmd);
	return TRUE;
	}else
	{
		return FALSE;
	}
}

?>