} } else { $smg = PMBP_addOutput(EX_NO_DB, "red"); if ($mode == "incl") { $out .= $msg; } else { echo $msg; } } // start backup using ftp or email $backup_info = array("comments" => $_POST['comments'], "tables" => $_POST['tables'] == "on", "data" => $_POST['data'] == "on", "drop" => $_POST['drop'] == "on", "comp" => $_POST['zip']); if ($CONF['ftp_use'] && isset($store_files)) { $out .= PMBP_FTP_store($store_files); } if ($CONF['email_use'] && isset($store_files)) { $out .= PMBP_email_store($store_files, $backup_info); } // file backup per FTP if ($CONF['dir_backup'] && (isset($_POST['dirs']) || strlen($_POST['man_dirs']))) { $_POST['man_dirs'] = str_replace("\n", ",", $_POST['man_dirs']); $files = array(); if (isset($_POST['dirs'])) { $_POST['dirs'] = array_merge(explode(",", $_POST['man_dirs']), $_POST['dirs']); foreach ($_POST['dirs'] as $dir) { $files = array_merge($files, PMBP_get_files($dir)); } } else { foreach (explode("|", $_POST['man_dirs']) as $dir) { $files = array_merge($files, PMBP_get_files(trim($dir))); } }
if ($CONF['dir_backup'] && (isset($_POST['dirs']) || strlen($_POST['man_dirs']))) { $_POST['man_dirs'] = str_replace("\n", ",", $_POST['man_dirs']); $files = array(); if (isset($_POST['dirs'])) { $_POST['dirs'] = array_merge(explode(",", $_POST['man_dirs']), $_POST['dirs']); foreach ($_POST['dirs'] as $dir) { $files = array_merge($files, PMBP_get_files($dir)); } } else { foreach (explode("|", $_POST['man_dirs']) as $dir) { $files = array_merge($files, PMBP_get_files($dir)); } } // backup files by emails if ($PMBP_SYS_VAR['dir_email_backup']) { $out .= PMBP_email_store($files, $_POST['comments']); } // backup files by FTP $out .= PMBP_save_FTP($files, $_POST['packed']); } // show execution duration if (function_exists("microtime")) { $microtime = explode(" ", microtime()); $endtime = $microtime[0] + $microtime[1]; } else { $endtime = time(); } if ($mode == "web") { echo $out . "\n"; echo "<div class=\"bold\">" . F_DURATION . ": " . number_format($endtime - $starttime, 3) . " " . F_SECONDS . "</div>\n"; echo "<br>";
function PMBP_save_FTP_and_Email($files, $packed = false, &$zipFile) { global $CONF; global $PMBP_SYS_VAR; global $mode; if (!isset($mode)) { $mode = "web"; } $out = FALSE; // try to connect to server using username and passwort if (!$CONF['ftp_server']) { $out .= PMBP_addOutput(C_WRONG_FTP, "red"); } elseif (!($conn_id = @ftp_connect($CONF['ftp_server'], $CONF['ftp_port'], $PMBP_SYS_VAR['ftp_timeout']))) { $out .= PMBP_addOutput(F_FTP_1 . " '" . $CONF['ftp_server'] . "'!", "red"); } else { if (!($login_result = @ftp_login($conn_id, $CONF['ftp_user'], $CONF['ftp_passwd']))) { $out .= PMBP_addOutput(F_FTP_2 . " '" . $CONF['ftp_user'] . "'", "red"); } else { // succesfully connected -> set passive and change to the right path if ($CONF['ftp_pasv']) { ftp_pasv($conn_id, TRUE); } else { ftp_pasv($conn_id, FALSE); } if (!$CONF['ftp_path']) { $path = "."; } else { $path = $CONF['ftp_path']; } @ftp_chdir($conn_id, $path); // backup as one ZIP file if ($packed) { include_once "pclzip.lib.php"; $filename = $CONF['sitename'] . "." . time() . ".zip"; $pclzip = new Pclzip(PMBP_EXPORT_DIR . $filename); $v_list = $pclzip->create($files); // try three times to upload zip files $check = FALSE; for ($i = 0; $i < 3; $i++) { if (!$check) { $check = ftp_put($conn_id, $filename, PMBP_EXPORT_DIR . $filename, FTP_BINARY); } } if ($check) { // adjust file permissions on ftp server //ftp_chmod($conn_id,substr(sprintf('%o', fileperms(PMBP_EXPORT_DIR.$filename)), -4),$filename); $out .= PMBP_addOutput(F_FTP_4 . " '" . $filename . "'", "green"); } else { $out .= PMBP_addOutput(F_FTP_3, "red"); } // backup files by emails if ($PMBP_SYS_VAR['dir_email_backup']) { $zipFile[] = PMBP_EXPORT_DIR . $filename; $out .= PMBP_email_store($zipFile, $_POST['comments']); } @unlink(PMBP_EXPORT_DIR . $filename); // backup each file } else { // create all missing folders foreach ($files as $filepath) { if ($filepath = trim($filepath)) { $folders = explode("/", $filepath); $filename = array_pop($folders); $deep = 0; $all_folders = ""; $all_folders_local = ""; foreach ($folders as $folder) { $all_folders_local .= $folder . "/"; if ($folder != "." && $folder != "..") { if (!@ftp_chdir($conn_id, $folder)) { @ftp_mkdir($conn_id, $folder); @ftp_chdir($conn_id, $folder); } // adjust directory permissions //ftp_chmod($conn_id,substr(sprintf('%o', fileperms("../".$folder)), -4),"../".$folder); $all_folders .= $folder . "/"; $deep++; } } // change back to $path $rel_path = ""; for ($i = 0; $i < $deep; $i++) { $rel_path .= "../"; } @ftp_chdir($conn_id, $rel_path); // define the source and destination pathes $dest_file = $all_folders . $filename; $source_file = "./" . $filepath; // try three times to upload $check = FALSE; for ($i = 0; $i < 3; $i++) { if (!$check) { $check = @ftp_put($conn_id, $dest_file, $source_file, FTP_BINARY); } } if ($check) { // adjust file permissions on ftp server //ftp_chmod($conn_id,substr(sprintf('%o', fileperms($source_file)), -4),$dest_file); $out .= PMBP_addOutput(F_FTP_4 . " '" . $dest_file . "'", "green"); } else { $out .= PMBP_addOutput(F_FTP_3 . ": '" . $source_file . "' -> '" . $dest_file . "'", "red"); } } } // backup files by emails if ($PMBP_SYS_VAR['dir_email_backup']) { $out .= PMBP_email_store($files, $_POST['comments']); } } // close the FTP connection if (@function_exists("ftp_close")) { @ftp_close($conn_id); } } } return $out; }