예제 #1
0
 /**
  * Optimize a table and write returned message to log file.
  *
  * Returns true on success or MySQL-Error.
  *
  * @param MsdDbFactory $dbo   Database object
  * @param string       $table Name of table
  *
  * @return bool
  */
 public static function optimizeTable(MsdDbFactory $dbo, $table)
 {
     global $lang, $log;
     $res = $dbo->optimizeTable($table);
     if (false !== $res) {
         $success = array('status', 'info', 'warning', 'note');
         if (in_array($res['Msg_type'], $success)) {
             $logMsg = $lang['L_OPTIMIZE'] . ' `' . $dbo->dbSelected . '`.`';
             $logMsg .= $table . '`: ' . $res['Msg_text'];
             $log->write(Log::PHP, $logMsg);
             return true;
         } else {
             $logMsg = sprintf($lang['L_OPTIMIZE_TABLE_ERR'], $table);
             writeToErrorLog($dbo->dbSelected, $logMsg, $res['msg_text'], 0);
             return false;
         }
     } else {
         $logMsg = sprintf($lang['L_OPTIMIZE_TABLE_ERR'], $table);
         writeToErrorLog($dbo->dbSelecte, $logMsg, $res['msg_text'], 0);
         return false;
     }
 }
/**
 * Deletes every table or view in a database
 *
 * @param string $dbn Databasename
 *
 * @return void
 */
function truncateDb($dbn)
{
    global $dbo;
    $t_sql = array();
    $dbo->query('SET FOREIGN_KEY_CHECKS=0', MsdDbFactory::SIMPLE);
    $res = $dbo->query('SHOW TABLE STATUS FROM `' . $dbn . '`', MsdDbFactory::ARRAY_ASSOC);
    foreach ($res as $row) {
        if (substr(strtoupper($row['Comment']), 0, 4) == 'VIEW') {
            $t_sql[] = 'DROP VIEW `' . $dbn . '``' . $row['Name'] . '`';
        } else {
            $t_sql[] = 'DROP TABLE `' . $dbn . '`.`' . $row['Name'] . '`';
        }
    }
    if (sizeof($t_sql) > 0) {
        for ($i = 0; $i < count($t_sql); $i++) {
            try {
                $dbo->query($t_sql[$i]);
            } catch (Excption $e) {
                //TODO create clean error handling depending on context
                writeToErrorLog($e->getMessage());
                die($e->getMessage());
            }
        }
    }
    $dbo->query('SET FOREIGN_KEY_CHECKS=1', MsdDbFactory::SIMPLE);
}
    $restore['EOB'] = true;
}
//part is >0 if we have a Multipart backup
if ($restore['EOB']) {
    // Done
    $time = getTimeFormat(time() - $restore['restore_start_time']);
    $log->write(Log::PHP, sprintf($lang['L_RESTORE_DB_COMPLETE_IN'], $config['db_actual'], $time));
    $restore['restore_in_progress'] = 0;
} else {
    if ($restore['fileEOF']) {
        // let's get the next Multipart file
        $restore['fileEOF'] = false;
        $nextfile = getNextPart($restore['filename'], 0, true);
        // there is more to do -> process the next Multipart file
        if (!file_exists($config['paths']['backup'] . $nextfile)) {
            writeToErrorLog($config['db_actual'], '', sprintf($lang['L_ERROR_MULTIPART_RESTORE'], $nextfile));
            $restore['restore_in_progress'] = 0;
        } else {
            $restore['filename'] = $nextfile;
            $restore['offset'] = 0;
            $restore['part']++;
            $log->write(Log::PHP, sprintf($lang['L_CONTINUE_MULTIPART_RESTORE'], $restore['filename']));
        }
    }
}
// collect values to return to client
$r = array();
$json = new Services_JSON();
$r['restore_in_progress'] = $restore['restore_in_progress'];
if ($restore['page_refreshs'] == 1) {
    // Only send on first page call because values won't change
예제 #4
0
     $dump['progress_table_percent'] = 0;
     $dump['speed'] = $config['minspeed'];
     // should we dump the table structure?
     if ($dump['databases'][$dump['db_actual']]['tables'][$table]['dump_structure'] > 0) {
         // get create statement of table
         try {
             $records = $dump['databases'][$dump['db_actual']]['tables'][$table]['dump_records'];
             $createStatement = getCreateString($dump['db_actual'], $table, $records);
             $dump['data'] .= $createStatement;
         } catch (Exception $e) {
             // error reading table definition
             writeToDumpFile();
             // save data we have up to now
             $logMsg = sprintf($lang['L_FATAL_ERROR_DUMP'], $table, $dump['db_actual']);
             $readCreateError = $logMsg . ': ' . $e->getMessage();
             writeToErrorLog($config['db_actual'], '', $readCreateError, 0);
             $log->write(Log::ERROR, $readCreateError);
             $dump['errors']++;
             //next table
             $dump['table_offset']++;
             $dump['table_record_offset'] = 0;
             // set records of table not to be dumped
             $dump['databases'][$dump['db_actual']]['tables'][$table]['dump_records'] = 0;
         }
     }
 }
 if ($dump['databases'][$dump['db_actual']]['tables'][$table]['dump_records'] == 1) {
     getContent($dump['db_actual'], $table);
 } else {
     //jump to next table if we don't need to dump the records of this table
     $dump['table_offset']++;
/**
 * Transfers a file via FTP and logs each action
 *
 * @param integer $ftpConnectionIndex Index of FTP-Connection in configuration
 * @param string  $sourceFile        File to transfer
 * @return void
 */
function sendViaFTP($ftpConnectionIndex, $sourceFile)
{
    global $config, $lang, $log;
    $upload = false;
    $i = $ftpConnectionIndex;
    // I am lazy ;)
    // connect to ftp server
    if ($config['ftp'][$i]['ssl'] == 0) {
        $connId = @ftp_connect($config['ftp'][$i]['server'], $config['ftp'][$i]['port'], $config['ftp'][$i]['timeout']);
    } else {
        $connId = @ftp_ssl_connect($config['ftp'][$i]['server'], $config['ftp'][$i]['port'], $config['ftp'][$i]['timeout']);
    }
    if (is_resource($connId)) {
        $log->write(Log::PHP, $lang['L_FTP'] . ': ' . sprintf($lang['L_FTP_CONNECTION_SUCCESS'], $config['ftp'][$i]['server'], $config['ftp'][$i]['port']));
    } else {
        $msg = sprintf($lang['L_FTP_CONNECTION_ERROR'], $config['ftp'][$i]['server'], $config['ftp'][$i]['port']);
        writeToErrorLog('', '', $lang['L_FTP'] . ': ' . $msg, 0);
    }
    // login using user and password
    $loginResult = @ftp_login($connId, $config['ftp'][$i]['user'], $config['ftp'][$i]['pass']);
    if (!$loginResult) {
        writeToErrorLog('', '', $lang['L_FTP'] . ': ' . sprintf($lang['L_FTP_LOGIN_ERROR'], $config['ftp'][$i]['user']), 0);
    } else {
        $log->write(Log::PHP, $lang['L_FTP'] . ': ' . sprintf($lang['L_FTP_LOGIN_SUCCESS'], $config['ftp'][$i]['user']));
    }
    if ($config['ftp'][$i]['mode'] == 1) {
        if (@ftp_pasv($connId, true)) {
            $log->write(Log::PHP, $lang['L_FTP'] . ': ' . $lang['L_FTP_PASV_SUCCESS']);
        } else {
            writeToErrorLog('', '', $lang['L_FTP'] . ': ' . $lang['L_FTP_PASV_ERROR'], 0);
        }
    }
    // Upload der Datei
    $dest = $config['ftp'][$i]['dir'] . $sourceFile;
    $source = $config['paths']['backup'] . $sourceFile;
    $upload = @ftp_put($connId, $dest, $source, FTP_BINARY);
    // Upload-Status überprüfen
    if (!$upload) {
        writeToErrorLog('', '', sprintf($lang['L_FTP_FILE_TRANSFER_ERROR'], $sourceFile), 0);
    } else {
        $log->write(Log::PHP, sprintf($lang['L_FTP_FILE_TRANSFER_SUCCESS'], $sourceFile));
    }
    // Schließen des FTP-Streams
    @ftp_quit($connId);
    $log->write(Log::PHP, $lang['L_FTP_CONNECTION_CLOSED']);
}