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 = $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); } // Now lets backup all MySQL datbases for the user and add them to the archive... $sql = "SELECT COUNT(*) FROM x_mysql_databases WHERE my_acc_fk=:userid AND 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_acc_fk=:userid AND 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"); } } } // 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) { /* Ajax not supporting headers - changed to link in temp dir. if (sys_versions::ShowOSPlatformVersion() == "Windows") { # Now we send the output (Windows)... header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private', false); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename=' . $backupname . '.zip'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($backupdir . $backupname . '.zip ') . ''); readfile($backupdir . $backupname . ".zip "); } else { # Now we send the output (POSIX)... $file = $backupdir . $backupname . ".zip"; header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private', false); header('Content-Description: File Transfer'); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/force-download'); header('Content-Length: ' . filesize($file)); header('Content-Disposition: attachment; filename=' . $backupname . '.zip'); readfile_chunked($file); } */ 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; }
$resault = exec("cd " . $homedir . "/ && " . ctrl_options::GetSystemOption('zip_exe') . " -r9 " . ctrl_options::GetSystemOption('temp_dir') . $backupname . " public_html/*"); @chmod(ctrl_options::GetSystemOption('temp_dir') . $backupname . ".zip", 0777); } // Now lets backup all MySQL datbases for the user and add them to the archive... $sql = "SELECT COUNT(*) FROM x_mysql_databases WHERE my_acc_fk=" . $userid . " AND my_deleted_ts IS NULL"; if ($numrows = $zdbh->query($sql)) { if ($numrows->fetchColumn() != 0) { $sql = $zdbh->prepare("SELECT * FROM x_mysql_databases WHERE my_acc_fk=:userid AND 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'] . " > " . ctrl_options::GetSystemOption('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 " . ctrl_options::GetSystemOption('temp_dir') . $backupname . ".zip " . ctrl_options::GetSystemOption('temp_dir') . $row_mysql['my_name_vc'] . "_" . $dbstamp . ".sql")); } else { $resault = exec("cd " . ctrl_options::GetSystemOption('temp_dir') . "/ && " . ctrl_options::GetSystemOption('zip_exe') . " " . ctrl_options::GetSystemOption('temp_dir') . $backupname . " " . $row_mysql['my_name_vc'] . "_" . $dbstamp . ".sql"); } unlink(ctrl_options::GetSystemOption('temp_dir') . $row_mysql['my_name_vc'] . "_" . $dbstamp . ".sql"); } } } // We have the backup now lets output it to disk or download if (file_exists(ctrl_options::GetSystemOption('temp_dir') . $backupname . ".zip")) { // Copy Backup to user home directory... $backupdir = $homedir . "/backups/"; if (!is_dir($backupdir)) { mkdir($backupdir, 0777, TRUE); } copy(ctrl_options::GetSystemOption('temp_dir') . $backupname . ".zip", $backupdir . $backupname . ".zip");