function cron_dump_autobackup() { global $db, $db_config, $global_config, $client_info; $result = true; $current_day = mktime(0, 0, 0, date("n", NV_CURRENTTIME), date("j", NV_CURRENTTIME), date("Y", NV_CURRENTTIME)); $w_day = $current_day - $global_config['dump_backup_day'] * 86400; $contents = array(); $contents['savetype'] = $global_config['dump_backup_ext'] == "sql" ? "sql" : "gz"; $file_ext = $contents['savetype'] == "sql" ? "sql" : "sql.gz"; $log_dir = NV_ROOTDIR . "/" . NV_LOGS_DIR . "/dump_backup"; $contents['filename'] = $log_dir . "/" . md5(nv_genpass(10) . $client_info['session_id']) . "_" . $current_day . "." . $file_ext; if (!file_exists($contents['filename'])) { $files = scandir($log_dir); foreach ($files as $file) { unset($mc); if (preg_match("/^([a-zA-Z0-9]+)\\_([0-9]+)\\.(" . nv_preg_quote($file_ext) . ")/", $file, $mc)) { if (intval($mc[2]) > 0 and intval($mc[2]) < $w_day) { @unlink($log_dir . "/" . $file); } } } $contents['tables'] = array(); $res = $db->sql_query("SHOW TABLES LIKE '" . $db_config['prefix'] . "_%'"); while ($item = $db->sql_fetchrow($res)) { $contents['tables'][] = $item[0]; } $db->sql_freeresult($res); $contents['type'] = "all"; include NV_ROOTDIR . "/includes/core/dump.php"; if (!nv_dump_save($contents)) { $result = false; } } return $result; }
/** * cron_dump_autobackup() * * @return */ function cron_dump_autobackup() { global $db, $db_config, $global_config, $client_info; $result = true; $current_day = mktime(0, 0, 0, date('n', NV_CURRENTTIME), date('j', NV_CURRENTTIME), date('Y', NV_CURRENTTIME)); $w_day = $current_day - $global_config['dump_backup_day'] * 86400; $contents = array(); $contents['savetype'] = $global_config['dump_backup_ext'] == 'sql' ? 'sql' : 'gz'; $file_ext = $contents['savetype'] == 'sql' ? 'sql' : 'sql.gz'; $log_dir = NV_ROOTDIR . '/' . NV_LOGS_DIR . '/dump_backup'; $contents['filename'] = $log_dir . '/' . md5(nv_genpass(10) . $client_info['session_id']) . '_' . $current_day . '.' . $file_ext; if (!file_exists($contents['filename'])) { if ($dh = opendir($log_dir)) { while (($file = readdir($dh)) !== false) { if (preg_match('/^([a-zA-Z0-9]+)\\_([0-9]+)\\.(' . nv_preg_quote($file_ext) . ')/', $file, $m)) { if (intval($m[2]) > 0 and intval($m[2]) < $w_day) { @unlink($log_dir . '/' . $file); } } } closedir($dh); clearstatcache(); } if ($global_config['dump_autobackup']) { $contents['tables'] = array(); $res = $db->query("SHOW TABLES LIKE '" . $db_config['prefix'] . "_%'"); while ($item = $res->fetch(3)) { $contents['tables'][] = $item[0]; } $res->closeCursor(); $contents['type'] = 'all'; include NV_ROOTDIR . '/includes/core/dump.php'; if (!nv_dump_save($contents)) { $result = false; } } } return $result; }
} elseif (!is_array($tables)) { $tables = array($tables); } $tab_list = array(); $result = $db->query("SHOW TABLES LIKE '" . $db_config['prefix'] . "_%'"); while ($item = $result->fetch(3)) { $tab_list[] = $item[0]; } $result->closeCursor(); $contents = array(); $contents['tables'] = empty($tables) ? $tab_list : array_values(array_intersect($tab_list, $tables)); $contents['type'] = $type != 'str' ? 'all' : 'str'; $contents['savetype'] = $ext != 'sql' ? 'gz' : 'sql'; $contents['filename'] = tempnam(NV_ROOTDIR . '/' . NV_TEMP_DIR, NV_TEMPNAM_PREFIX); include NV_ROOTDIR . '/includes/core/dump.php'; $result = nv_dump_save($contents); if (!empty($result)) { nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['download'], 'File name: ' . basename($contents['filename']), $admin_info['userid']); $content['mime'] = $contents['savetype'] == 'gz' ? 'application/x-gzip' : 'text/x-sql'; $contents['fname'] = $db->dbname . '.sql'; if ($contents['savetype'] == 'gz') { $contents['fname'] .= '.gz'; } //Download file require_once NV_ROOTDIR . '/includes/class/download.class.php'; $download = new download($result[0], NV_ROOTDIR . '/' . NV_TEMP_DIR, basename($contents['fname'])); $download->download_file(); exit; } } die;
$current_day = mktime(0, 0, 0, date('n', NV_CURRENTTIME), date('j', NV_CURRENTTIME), date('Y', NV_CURRENTTIME)); $contents = array(); $contents['savetype'] = $type == 'sql' ? 'sql' : 'gz'; $file_ext = $contents['savetype'] == 'sql' ? 'sql' : 'sql.gz'; $log_dir = NV_ROOTDIR . '/' . NV_LOGS_DIR . '/dump_backup'; $contents['filename'] = $log_dir . '/' . md5(nv_genpass(10) . $client_info['session_id']) . '_' . $current_day . '.' . $file_ext; if (!file_exists($contents['filename'])) { $contents['tables'] = array(); $res = $db->query("SHOW TABLES LIKE '" . $db_config['prefix'] . "_%'"); while ($item = $res->fetch(3)) { $contents['tables'][] = $item[0]; } $res->closeCursor(); $contents['type'] = 'all'; include NV_ROOTDIR . '/includes/core/dump.php'; $dump = nv_dump_save($contents); // Ghi log $NvUpdate->log($nv_update_config, $lang_module['update_dump'] . ' ' . $contents['savetype'], $dump); if ($dump == false) { die($lang_module['update_dump_error']); } else { $file = str_replace(NV_ROOTDIR . '/' . NV_LOGS_DIR . '/dump_backup/', '', $dump[0]); // Danh dau da sao luu CSDL $nv_update_config['updatelog']['data_backuped'] = NV_CURRENTTIME; $NvUpdate->set_data_log($nv_update_config['updatelog']); die($lang_module['update_dump_ok'] . ' ' . nv_convertfromBytes($dump[1]) . '<br /><a href="' . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=database&" . NV_OP_VARIABLE . "=getfile&filename=" . $file . "&checkss=" . md5($file . $client_info['session_id'] . $global_config['sitekey']) . '" title="' . $lang_module['update_dump_download'] . '">' . $lang_module['update_dump_download'] . '</a>'); } } else { die($lang_module['update_dump_exist']); } }