Current File : //root/backup/fullrestore.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;
}

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;
global $controller;
if (isset($argv[1]) && $argv[1] != "") {
  
		$username=trim($argv[1]);
		$vhost_path = ctrl_options::GetSystemOption('hosted_dir'); // use this code for get the value
				$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'];		
					$filename=$argv[2];		
					 echo "Restore started. \n";
					 $dest_path=$vhost_path.$username."/";
					# $dest_path="/backup/".$username."/";
					$src_path="/backup/".$username."/";
					$cmd="cd $src_path && unzip -n $filename -d $dest_path 2>&1 ";
					$output=array();
					$return_val="";
					$output=passthru($cmd,$return_val);
					exec("chown -R apache:apache $dest_path");
					exec("chmod -R 0755 $dest_path");
					$mail_path=$dest_path."Mail.zip";
					if(file_exists($mail_path))
					{
						$mail_dest_path="/var/sentora/vmail/";
						$src_path="/backup/".$username."/";
						$cmd="cd $dest_path && unzip -n Mail.zip -d $mail_dest_path 2>&1 ";
						$output=array();
						$return_val="";
						$output=passthru($cmd,$return_val);
						passthru("chown -R vmail:mail $mail_dest_path");
						passthru("chmod -R 0755 $mail_dest_path");
						exec("rm -fr $mail_path ");
					}else
					{
						echo "Mailbackup not available";
					}


					$dbname=md5(sha1($username."SQL")).".sql";
					if(file_exists($vhost_path.$username."/mysql/".$dbname))
					{
					$cmd="mysql -u $user -p$pass < ".$vhost_path.$username."/mysql/$dbname"; 
					$output=passthru($cmd,$return_val);
					$output=array();
					$return_val="";
					$output=passthru($cmd,$return_val);
					$cmd="rm -fr ".$vhost_path.$username."/mysql";
					exec($cmd);
					return TRUE;
					}
	}
	else
	{
	echo "Username does not exists.";
	exit();		
	}
}


?>