Current File : //root/panel/modules/backupwizard/code/fullbackup.php |
<?php
echo "<script src=\"http://code.jquery.com/jquery-latest.js\"></script>";
set_time_limit(0);
ini_set('memory_limit', '256M');
require('../../../cnf/db.php');
include('../../../dryden/db/driver.class.php');
include('../../../dryden/debug/logger.class.php');
include('../../../dryden/runtime/dataobject.class.php');
include('../../../dryden/runtime/hook.class.php');
include('../../../dryden/sys/versions.class.php');
include('../../../dryden/ctrl/options.class.php');
include('../../../dryden/fs/director.class.php');
include('../../../dryden/fs/filehandler.class.php');
include('../../../inc/dbc.inc.php');
try {
$zdbh = new db_driver("mysql:host=" . $host . ";dbname=" . $dbname . "", $user, $pass);
} catch (PDOException $e) {
exit();
}
$download=1;
if (isset($_GET['id']) && $_GET['id'] != "") {
session_start();
if ($_SESSION['zpuid'] == $_GET['id']) {
$userid = $_GET['id'];
$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_id_pk= :userid
");
$rows->bindParam(':userid', $userid);
$rows->execute();
$dbvals = $rows->fetch();
if ($backup = ExecuteBackup($userid, $dbvals['ac_user_vc'], $download)) {
$full_path_file='../../../etc/tmp/'. basename($backup);
$file_for_user=basename($backup);
header('Content-Description: File Transfer');
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="'.$file_for_user.'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
//header('Content-Length: ' . filesize($full_path_file));
readfile($full_path_file);
exit();
} else {
echo "<h2>Unauthorized Access!</h2>";
echo "You have no permission to view this module.";
}
}
}
function ExecuteBackup($userid, $username, $download = 0) {
include('../../../cnf/db.php');
try {
$zdbh = new db_driver("mysql:host=" . $host . ";dbname=" . $dbname . "", $user, $pass);
} catch (PDOException $e) {
exit();
}
$basedir = ctrl_options::GetSystemOption('temp_dir');
if (!is_dir($basedir)) {
fs_director::CreateDirectory($basedir);
}
$basedir = ctrl_options::GetSystemOption('sentora_root') . "etc/tmp/";
if (!is_dir($basedir)) {
fs_director::CreateDirectory($basedir);
}
$temp_dir = ctrl_options::GetSystemOption('sentora_root') . "etc/tmp/";
// Lets grab and archive the user's web data....
$homedir = ctrl_options::GetSystemOption('hosted_dir') . $username;
$backupname = "Full".$username . "_" . date("M-d-Y_hms", time());
$dbstamp = date("dmy_Gi", time());
// We now see what the OS is before we work out what compression command to use..
if (sys_versions::ShowOSPlatformVersion() == "Windows") {
$resault = exec(fs_director::SlashesToWin(ctrl_options::GetSystemOption('zip_exe') . " a -tzip -y-r " . $temp_dir . $backupname . ".zip " . $homedir . "/public_html"));
} else {//cd /var/sentora/hostdata/zadmin/; zip -r backups/backup.zip public_html/
$resault = exec("cd " . $homedir . "/ && " . ctrl_options::GetSystemOption('zip_exe') . " -r9 " . $temp_dir . $backupname . " public_html/*");
@chmod($temp_dir . $backupname . ".zip", 0777);
}
// We have the backup now lets output it to disk or download
// Now lets backup all MySQL datbases for the user and add them to the archive...
/* //////////////////////////////////////////////////////////// My Sql Start //////////////////////////////////////////////////////*/
$sql = "SELECT COUNT(*) FROM x_mysql_databases WHERE my_deleted_ts IS NULL";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':userid', $userid);
$numrows->execute();
if ($numrows) {
if ($numrows->fetchColumn() <> 0) {
$sql = $zdbh->prepare("SELECT * FROM x_mysql_databases WHERE my_deleted_ts IS NULL");
$sql->bindParam(':userid', $userid);
$sql->execute();
while ($row_mysql = $sql->fetch()) {
$bkcommand = ctrl_options::GetSystemOption('mysqldump_exe') . " -h " . $host . " -u " . $user . " -p" . $pass . " --no-create-db " . $row_mysql['my_name_vc'] . " > " . $temp_dir . $row_mysql['my_name_vc'] . "_" . $dbstamp . ".sql";
passthru($bkcommand);
// Add it to the ZIP archive...
if (sys_versions::ShowOSPlatformVersion() == "Windows") {
$resault = exec(fs_director::SlashesToWin(ctrl_options::GetSystemOption('zip_exe') . " u " . $temp_dir . $backupname . ".zip " . $temp_dir . $row_mysql['my_name_vc'] . "_" . $dbstamp . ".sql"));
} else {
$resault = exec("cd " . $temp_dir . "/ && " . ctrl_options::GetSystemOption('zip_exe') . " " . $temp_dir . $backupname . " " . $row_mysql['my_name_vc'] . "_" . $dbstamp . ".sql");
}
unlink($temp_dir . $row_mysql['my_name_vc'] . "_" . $dbstamp . ".sql");
}
}
}
/* //////////////////////////////////////////////////////////// My Sql End //////////////////////////////////////////////////////*/
/* //////////////////////////////////////////////////////////// Email Start //////////////////////////////////////////////////////*/
$temp_dir = ctrl_options::GetSystemOption('sentora_root') . "etc/tmp/";
$homedir ='/var/sentora';
//$backupname = "Mail_".$username . "_" . date("M-d-Y_hms", time());
$dbstamp = date("dmy_Gi", time());
if (sys_versions::ShowOSPlatformVersion() == "Windows") {
//fs_director::SlashesToWin(ctrl_options::GetSystemOption('zip_exe') . " a -tzip -y-r " . $temp_dir . $backupname . ".zip " . $homedir . "/vmail");
$resault = exec(fs_director::SlashesToWin(ctrl_options::GetSystemOption('zip_exe') . " a -tzip -y-r " . $temp_dir . $backupname . ".zip " . $homedir . "/vmail"));
}
else {
$resault = exec("cd " . $homedir . "/ && " . ctrl_options::GetSystemOption('zip_exe') . " -r9 " . $temp_dir . $backupname . " vmail/*");
//@chmod($temp_dir . $backupname . ".zip", 0777);
}
/* //////////////////////////////////////////////////////////// Email End //////////////////////////////////////////////////////*/
// We have the backup now lets output it to disk or download
if (file_exists($temp_dir . $backupname . ".zip")) {
// If Disk based backups are allowed in backup config
if (strtolower(ctrl_options::GetSystemOption('disk_bu')) == "true") {
// Copy Backup to user home directory...
$backupdir = $homedir . "/backups/";
if (!is_dir($backupdir)) {
fs_director::CreateDirectory($backupdir);
@chmod($backupdir, 0777);
}
copy($temp_dir . $backupname . ".zip", $backupdir . $backupname . ".zip");
fs_director::SetFileSystemPermissions($backupdir . $backupname . ".zip", 0777);
} else {
$backupdir = $temp_dir;
}
// If Client has checked to download file
if ($download <> 0) {
fs_director::SetFileSystemPermissions($backupdir . $backupname . ".zip", 0777);
return $temp_dir . $backupname . ".zip";
}
unlink($temp_dir . $backupname . ".zip");
} else {
echo "File not found in temp directory!";
return FALSE;
}
return TRUE;
}
function readfile_chunked($filename) {
$chunksize = 1 * (1024 * 1024);
$buffer = '';
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
print $buffer;
}
return fclose($handle);
}
?>