Exemplo n.º 1
0
/**
 * Backup database data which will be affected during upgrade
 *
 * @param string $path path to backup directory
 * @param Logger $log
 * @return array backed up tables list
 */
function fn_uc_backup_database($path, $log)
{
    $log->write('Backing up database: ' . $path, __FILE__, __LINE__);
    $tables = array();
    $db_files = array('db_scheme.sql', 'db_data.sql', 'db_lang_en.sql', 'db_lang_ru.sql');
    foreach ($db_files as $db_file) {
        if (file_exists($path . '/' . $db_file)) {
            $f = fopen($path . '/' . $db_file, 'rb');
            if (!empty($f)) {
                while (!feof($f)) {
                    $s = fgets($f);
                    if (preg_match_all("/(INSERT INTO|REPLACE INTO|UPDATE|ALTER TABLE|RENAME TABLE|DELETE FROM|DELETE [\\w, ]+ FROM|DROP TABLE|CREATE TABLE)( IF EXISTS| IF NOT EXISTS)? [`]?(\\w+)[`]?/", $s, $m)) {
                        $tables[$m[3][0]] = true;
                    }
                }
                fclose($f);
            }
        }
    }
    $tables = array_keys($tables);
    @fn_uc_rm($path . '/backup/uc.sql');
    @fn_uc_rm($path . '/db_backup_tables.txt');
    $bak_tables = fn_uc_backup_tables($tables, $path, $path . '/backup/uc.sql', $log);
    if (false === $bak_tables) {
        fn_set_notification('E', __('error'), __('text_uc_failed_to_backup_tables'));
        return false;
    }
    return $bak_tables;
}
Exemplo n.º 2
0
/**
 * Backup database data which will be affected during upgrade
 *
 * @param string $path path to backup directory
 * @return array backed up tables list
 */
function fn_uc_backup_database($path)
{
    $tables = array();
    if (file_exists($path . '/uc.sql')) {
        $f = fopen($path . '/uc.sql', 'rb');
        if (!empty($f)) {
            while (!feof($f)) {
                $s = fgets($f);
                if (preg_match_all("/(INSERT INTO|REPLACE INTO|UPDATE|ALTER TABLE|RENAME TABLE|DELETE FROM|DROP TABLE|CREATE TABLE)( IF EXISTS| IF NOT EXISTS)? [`]?(\\w+)[`]?/", $s, $m)) {
                    $tables[$m[3][0]] = true;
                }
            }
            fclose($f);
        }
    }
    $tables = array_keys($tables);
    @fn_uc_rm($path . '/backup/uc.sql');
    return fn_uc_backup_tables($tables, $path . '/backup/uc.sql');
}