function doBackup($tables, $OutType, $OutDest, $toBackUp, $UserAgent, $local_backup_path, &$databaseResult, $backupname, $excltables = array(), $dbname) { global $database, $mosConfig_db, $mosConfig_sitename, $version, $option, $task, $mosConfig_dbprefix, $_CONFIG, $mosConfig_user, $mosConfig_password, $mosConfig_host; if (!$tables[0]) { $databaseResult = LM_DATABASE_MISSING_TABLES; return; } /* Determine the mime type and file extension for the output file */ if ($OutType == "zip") { $filename = $backupname . "-sql" . ".zip"; } elseif ($OutType == "html") { $filename = $backupname . "-sql" . ".html"; } else { $filename = $backupname . "-sql" . ".sql"; } $sqlfile = "{$local_backup_path}/{$filename}"; @unlink($sqlfile); /* Store all the tables we want to back-up in variable $tables[] */ if ($tables[0] == "all") { array_pop($tables); $query = mysql_query("SHOW tables"); while ($row = mysql_fetch_array($query)) { $tables_list[] = $row[0]; } $tables = array_merge($tables, $tables_list); } $newtables = array(); #if(is_array($excltables)) foreach ($tables as $key => $value) { if (is_array($excltables)) { if (!in_array($value, $excltables)) { $newtables[] = $value; } } else { $newtables[] = $value; } } if (sizeof($tables) == sizeof($newtables)) { $ex_dump = ""; } else { $ex_dump = @implode(" ", $newtables); } $tables = $newtables; if ($_REQUEST['dbbackup_drop']) { $drop = " --add-drop-table"; } else { $drop = ""; } if ($_REQUEST['dbbackup_comp']) { $drop .= " --compatible=" . strtolower($_REQUEST['dbbackup_comp']) . " "; } if ($_CONFIG['sql_mem']) { exec($_CONFIG[sqldump] . " -h " . $_CONFIG['mysql_host'] . " -u " . $_CONFIG['mysql_user'] . " -p" . $_CONFIG['mysql_pass'] . " " . $dbname . " > " . $sqlfile . " {$drop} --allow-keywords " . $ex_dump); if (filesize($sqlfile)) { $databaseResult = LM_DATABASE_BACKUP_COMPLETED . ' ( ' . getFileSizeText(filesize($sqlfile)) . ' )'; } else { $databaseResult = LM_MSG_BACK_14; } exec("chmod 777 {$sqlfile}"); return $sqlfile; } /*Added some default values for quotes and auto_increment problems*/ mysql_query("SET SQL_QUOTE_SHOW_CREATE=1;"); mysql_query("SET sql_mode = 0;"); if ($_REQUEST['dbbackup_comp']) { mysql_query("SET sql_mode=" . $_REQUEST['dbbackup_comp'] . ";"); } /* Store the "Create Tables" SQL in variable $CreateTable[$tblval] */ if ($toBackUp != "data") { foreach ($tables as $tblval) { $query = mysql_query("SHOW CREATE table `{$tblval}`"); $row = mysql_fetch_array($query); $CreateTable[$tblval] = $row[1]; } } /* Store all the FIELD TYPES being backed-up (text fields need to be delimited) in variable $FieldType*/ if ($toBackUp != "structure") { foreach ($tables as $tblval) { $query = mysql_query("SHOW FIELDS FROM {$tblval}"); while ($row = mysql_fetch_row($query)) { $fields[] = $row[0]; } foreach ($fields as $field) { $FieldType[$tblval][$field->Field] = preg_replace("/[(0-9)]/", '', $field->Type); } } } if ($OutDest == "local") { $fp = fopen($sqlfile, "w"); if (!$fp) { $databaseResult = LM_DATABASE_BACKUP_FAILED; return; } } /* Build the fancy header on the dump file */ $OutBuffer = ""; if ($OutType == 'html') { } else { $OutBuffer .= "#\n"; $OutBuffer .= "# Powered by XCloner Site Backup\n"; $OutBuffer .= "# http://www.joomlaplug.com\n"; $OutBuffer .= "#\n"; $OutBuffer .= "# Host: " . $_SERVER['HTTP_HOST'] . "\n"; $OutBuffer .= "# Generation Time: " . date("M j, Y \\a\\t H:i") . "\n"; $OutBuffer .= "# Server version: " . getVersion() . "\n"; $OutBuffer .= "# PHP Version: " . phpversion() . "\n"; $OutBuffer .= "# Database : `" . $dbname . "`\n# --------------------------------------------------------\n"; } fwrite($fp, $OutBuffer); unset($OutBuffer); /* Okay, here's the meat & potatoes */ foreach ($tables as $tblval) { if ($toBackUp != "data") { if ($OutType == 'html') { } else { $OutBuffer .= "#\n# Table structure for table `{$tblval}`\n#\n"; if ($_REQUEST['dbbackup_drop']) { $OutBuffer .= "#\nDROP table IF EXISTS {$tblval};\n"; } $OutBuffer .= $CreateTable[$tblval] . ";\r\n"; } } fwrite($fp, $OutBuffer); unset($OutBuffer); if ($toBackUp != "structure") { $OutBuffer .= "#\n# Dumping data for table `{$tblval}`\n#\n"; $query = @mysql_query("SELECT * FROM {$tblval}"); while ($row = @mysql_fetch_array($query, MYSQL_ASSOC)) { $InsertDump = "INSERT INTO {$tblval} VALUES ("; $arr = $row; foreach ($arr as $key => $value) { $value = addslashes($value); $value = str_replace("\n", '\\r\\n', $value); $value = str_replace("\r", '', $value); $InsertDump .= "'{$value}',"; /*else { $InsertDump .= "'$value',"; } */ } $OutBuffer .= rtrim($InsertDump, ',') . ");\n"; fwrite($fp, $OutBuffer); unset($OutBuffer); $i++; } } } if ($OutDest == "local") { #fwrite($fp, $OutBuffer); fclose($fp); @chmod($sqlfile, 0777); $databaseResult = LM_DATABASE_BACKUP_COMPLETED . ' ( ' . getFileSizeText(filesize($sqlfile)) . ' )'; return $sqlfile; } }
if ($_CONFIG['cron_btype'] == 2) { $_REQUEST[dbbackup] = 1; #for ($i=0, $n=count($excludedFolders); $i < $n; $i++) { $_CONFIG['cron_exclude'] = $_CONFIG['backup_path']; $GLOBALS['_CONFIG'] = $_CONFIG; $_REQUEST[cron_dbonly] = 1; #} logxx("Creating an sql only backup"); $msg = "database backup"; } logxx("Generating Backup ..."); $file = generateBackup($excludedFolders, 'nohtml'); logxx("Backup Done"); $source_file = $clonerPath . "/" . $file; logxx("Backup file: " . $source_file); $bsize = getFileSizeText(filesize($source_file)); if ($_CONFIG['cron_send'] == 1) { ######################################STARTING FTP TRANSFER################## $source_files[] = $source_file; $destination_files[] = $_CONFIG[cron_ftp_path] . "/" . $file; // set up basic connection details list($fhost, $fport) = explode(":", $_CONFIG[cron_ftp_server]); if ($fport == "") { $fport = '21'; } $ftp_timeout = '3600'; logxx("Starting ftp transfer:"); if (!$_CONFIG[secure_ftp]) { // set up basic connection $conn_id = ftp_connect($fhost, (int) $fport, (int) $ftp_timeout); $connect = "Normal";