Example #1
0
/**
*   Perform database backup
*
*   @return string  HTML success or error message
*/
function DBADMIN_backup()
{
    global $_VARS, $_CONF, $LANG08, $LANG_DB_BACKUP, $MESSAGE, $_IMAGE_TYPE, $_DB_host, $_DB_name, $_DB_user, $_DB_pass, $_DB_mysqldump_path;
    $retval = '';
    if (is_dir($_CONF['backup_path'])) {
        $curdatetime = date('Y_m_d_H_i_s');
        $backupfile = "{$_VARS['lglib_backup_path']}glfusion_db_backup_{$curdatetime}.sql";
        $command = '"' . $_DB_mysqldump_path . '" ' . " -h{$_DB_host} -u{$_DB_user}";
        if (!empty($_DB_pass)) {
            $command .= " -p" . escapeshellarg($_DB_pass);
            $parg = " -p" . escapeshellarg($_DB_pass);
        }
        if (!empty($_CONF['mysqldump_options'])) {
            $command .= ' ' . $_CONF['mysqldump_options'];
        }
        $command .= " {$_DB_name} > \"{$backupfile}\"";
        $log_command = $command;
        if (!empty($_DB_pass)) {
            $log_command = str_replace($parg, ' -p*****', $command);
        }
        if (function_exists('is_executable')) {
            $canExec = @is_executable($_DB_mysqldump_path);
        } else {
            $canExec = @file_exists($_DB_mysqldump_path);
        }
        if ($canExec) {
            DBADMIN_exec($command);
            // See if we got a backup file, and if it's reasonable (size > 1KB)
            if (file_exists($backupfile) && filesize($backupfile) > 1024) {
                @chmod($backupfile, 0644);
                $retval .= COM_showMessage(93);
            } else {
                $retval .= COM_showMessage(94);
                COM_errorLog('Backup Filesize was less than 1kb', 1);
                COM_errorLog("Command used for mysqldump: {$log_command}", 1);
            }
        } else {
            $retval .= COM_startBlock($LANG08[06], '', COM_getBlockTemplate('_msg_block', 'header'));
            $retval .= $LANG_DB_BACKUP['not_found'];
            $retval .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer'));
            COM_errorLog('Backup Error: Bad path, mysqldump does not exist or open_basedir restriction in effect.', 1);
            COM_errorLog("Command used for mysqldump: {$log_command}", 1);
        }
    } else {
        $retval .= COM_startBlock($MESSAGE[30], '', COM_getBlockTemplate('_msg_block', 'header'));
        $retval .= $LANG_DB_BACKUP['path_not_found'];
        $retval .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer'));
        COM_errorLog("Backup directory '" . $_CONF['backup_path'] . "' does not exist or is not a directory", 1);
    }
    return $retval;
}
Example #2
0
function DBADMIN_execWrapper($cmd)
{
    list($results, $status) = DBADMIN_exec($cmd);
    if ($status == 0) {
        return true;
    } else {
        COM_errorLog("DBADMIN_execWrapper: Failed Command: " . $cmd);
        return false;
    }
}