function backupDatabase() { require '/home/simpleco/demo2/app/includes_php/db.inc.php'; // Get a list ofall of the tables $sql = 'SHOW TABLES'; $s = $pdo->prepare($sql); $s->execute(); $table_names = $s->fetchAll(PDO::FETCH_ASSOC); // Create a CSV backup file for each table foreach ($table_names as $row) { backupTable($row['Tables_in_simpleco_demo3']); } }
/** * Backup the database - why not... */ function action_backupDatabase() { global $upcontext, $db_prefix, $command_line, $is_debug, $support_js, $file_steps; $upcontext['sub_template'] = isset($_GET['xml']) ? 'backup_xml' : 'backup_database'; $upcontext['page_title'] = 'Backup Database'; // Done it already - js wise? if (!empty($_POST['backup_done'])) { return true; } // Some useful stuff here. $db = database(); // Get all the table names. $filter = str_replace('_', '\\_', preg_match('~^`(.+?)`\\.(.+?)$~', $db_prefix, $match) != 0 ? $match[2] : $db_prefix) . '%'; $db = preg_match('~^`(.+?)`\\.(.+?)$~', $db_prefix, $match) != 0 ? strtr($match[1], array('`' => '')) : false; $tables = $db->db_list_tables($db, $filter); $table_names = array(); foreach ($tables as $table) { if (substr($table, 0, 7) !== 'backup_') { $table_names[] = $table; } } $upcontext['table_count'] = count($table_names); $upcontext['cur_table_num'] = $_GET['substep']; $upcontext['cur_table_name'] = str_replace($db_prefix, '', isset($table_names[$_GET['substep']]) ? $table_names[$_GET['substep']] : $table_names[0]); $upcontext['step_progress'] = (int) ($upcontext['cur_table_num'] / $upcontext['table_count'] * 100); // For non-java auto submit... $file_steps = $upcontext['table_count']; // What ones have we already done? foreach ($table_names as $id => $table) { if ($id < $_GET['substep']) { $upcontext['previous_tables'][] = $table; } } if ($command_line) { echo 'Backing Up Tables.'; } // If we don't support javascript we backup here. if (!$support_js || isset($_GET['xml'])) { // Backup each table! for ($substep = $_GET['substep'], $n = count($table_names); $substep < $n; $substep++) { $upcontext['cur_table_name'] = str_replace($db_prefix, '', isset($table_names[$substep + 1]) ? $table_names[$substep + 1] : $table_names[$substep]); $upcontext['cur_table_num'] = $substep + 1; $upcontext['step_progress'] = (int) ($upcontext['cur_table_num'] / $upcontext['table_count'] * 100); // Do we need to pause? nextSubstep($substep); backupTable($table_names[$substep]); // If this is XML to keep it nice for the user do one table at a time anyway! if (isset($_GET['xml'])) { return upgradeExit(); } } if ($is_debug && $command_line) { echo "\n" . ' Successful.\'' . "\n"; flush(); } $upcontext['step_progress'] = 100; $_GET['substep'] = 0; // Make sure we move on! return true; } // Either way next place to post will be database changes! $_GET['substep'] = 0; return false; }
function month_visited() { $unix = new unix(); LoadParams(); $DaysbackupOlder = $GLOBALS["DaysbackupOlder"]; $workdir = $GLOBALS["WORKDIR"]; $q = new mysql_squid_builder(); $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT MONTH( NOW( ) ) AS tmonth, YEAR( NOW( ) ) AS tyear", "artica_events")); if (strlen($ligne["tmonth"]) == 1) { $ligne["tmonth"] = "0" . $ligne["tmonth"]; } $current_table = "{$ligne["tyear"]}{$ligne["tmonth"]}_day"; $sql = "SELECT MONTH( zDate ) AS tmonth, YEAR( zDate ) AS tyear FROM tables_day \n\tWHERE zDate < DATE_SUB( NOW( ) , INTERVAL 200 DAY ) GROUP BY tmonth, tyear"; $GLOBALS["BACKUPED_SIZE"] = 0; $GLOBALS["TABLECOUNT"] = 0; $results = $q->QUERY_SQL($sql); if (!$q->ok) { ufdbguard_admin_events("Fatal, {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "backup"); return; } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $alt_table0 = null; $alt_table1 = null; if (strlen($ligne["tmonth"]) == 1) { $ligne["tmonth"] = "0" . $ligne["tmonth"]; } $tablename = "{$ligne["tyear"]}{$ligne["tmonth"]}_day"; if ($tablename == $current_table) { continue; } if ($GLOBALS["VERBOSE"]) { echo "{$tablename}\n"; } $filename = "{$workdir}/{$tablename}.gz"; if (is_file($filename)) { @unlink($filename); } if (backupTable($tablename, $filename)) { if (is_file($filename)) { $filesize = $unix->file_size($filename); $GLOBALS["BACKUPED_SIZE"] = $GLOBALS["BACKUPED_SIZE"] + $filesize; $GLOBALS["TABLECOUNT"]++; } } $tablename = "{$ligne["tyear"]}{$ligne["tmonth"]}_members"; if ($GLOBALS["VERBOSE"]) { echo "{$tablename}\n"; } $filename = "{$workdir}/{$tablename}.gz"; if (is_file($filename)) { @unlink($filename); } if (backupTable($tablename, $filename)) { if (is_file($filename)) { $filesize = $unix->file_size($filename); $GLOBALS["BACKUPED_SIZE"] = $GLOBALS["BACKUPED_SIZE"] + $filesize; $GLOBALS["TABLECOUNT"]++; } } $tablename = "{$ligne["tyear"]}{$ligne["tmonth"]}_blocked_days"; if ($GLOBALS["VERBOSE"]) { echo "{$tablename}\n"; } $filename = "{$workdir}/{$tablename}.gz"; if (is_file($filename)) { @unlink($filename); } if (backupTable($tablename, $filename)) { if (is_file($filename)) { $filesize = $unix->file_size($filename); $GLOBALS["BACKUPED_SIZE"] = $GLOBALS["BACKUPED_SIZE"] + $filesize; $GLOBALS["TABLECOUNT"]++; } } if (system_is_overloaded(basename(__FILE__))) { sleep(15); if (system_is_overloaded(__FILE__)) { sleep(10); if (system_is_overloaded(__FILE__)) { sleep(5); } } } if (system_is_overloaded(basename(__FILE__))) { ufdbguard_admin_events("Fatal, Overloaded system, aborting task and restart in newt cycle...", __FUNCTION__, __FILE__, __LINE__, "backup"); return; } } }