Beispiel #1
0
                    $fp = fopen($file_name, 'w');
                    for ($counter = 0; $counter < count($file_contents); $counter++) {
                        fwrite($fp, $file_contents[$counter]);
                        if ($total_rows >= $max_rows) {
                            $messages[] = array('message' => $file_contents[$counter], 'type' => 'info');
                        }
                    }
                    fclose($fp);
                }
                if ($total_rows >= $max_rows) {
                    break;
                }
            }
        }
    } else {
        if (gzcompressfile($filename, 9) == false) {
            $messages[] = array('message' => $lang->get_value('LNG_ADMIN_GZIPPED_FILE_COULD_NOT_BE_CREATED'), 'type' => 'action', 'result' => 'failed');
        } else {
            $messages[] = array('message' => $lang->get_value('LNG_ADMIN_GZIPPED_FILE_WAS_SUCCESSFULLY_CREATED'), 'type' => 'action', 'result' => 'success');
            $scripts[] = '<script type="text/javascript">parent.backup_completed();</script>';
            @unlink($filename);
        }
    }
    if ($restart != -1 && $count < $table_count) {
        $scripts[] = '<script>location.href="' . VIVVO_URL . VIVVO_FS_ADMIN_DIR . 'db_maintence.php?backup&restart=0&backup&f=' . $basename . '"</script>';
    } elseif ($restart != -1) {
        $scripts[] = '<script>location.href="' . VIVVO_URL . VIVVO_FS_ADMIN_DIR . 'db_maintence.php?backup&restart=-1&backup&f=' . $basename . '"</script>';
    }
} elseif (isset($_REQUEST['restore'])) {
    $action = 'restore';
    if (isset($_REQUEST['file']) && file_exists(VIVVO_FS_ROOT . 'backup/' . $_REQUEST['file'])) {
Beispiel #2
0
 /**
  *
  */
 public function cleanupLogFiles()
 {
     $files = glob(PIMCORE_LOG_DIRECTORY . "/*.log-archive-*");
     if (is_array($files)) {
         foreach ($files as $file) {
             if (filemtime($file) < time() - 86400 * 30) {
                 // we keep the logs for 30 days
                 unlink($file);
             } else {
                 if (!preg_match("/\\.gz\$/", $file)) {
                     gzcompressfile($file);
                     unlink($file);
                 }
             }
         }
     }
 }
Beispiel #3
0
 public function maintenanceCompress()
 {
     $perIteration = 100;
     $alreadyCompressedCounter = 0;
     $overallCounter = 0;
     $list = new Version\Listing();
     $list->setCondition("date < " . (time() - 86400 * 30));
     $list->setOrderKey("date");
     $list->setOrder("DESC");
     $list->setLimit($perIteration);
     $total = $list->getTotalCount();
     $iterations = ceil($total / $perIteration);
     for ($i = 0; $i < $iterations; $i++) {
         \Logger::debug("iteration " . ($i + 1) . " of " . $iterations);
         $list->setOffset($i * $perIteration);
         $versions = $list->load();
         foreach ($versions as $version) {
             $overallCounter++;
             if (file_exists($version->getFilePath())) {
                 gzcompressfile($version->getFilePath(), 9);
                 @unlink($version->getFilePath());
                 $alreadyCompressedCounter = 0;
                 \Logger::debug("version compressed:" . $version->getFilePath());
             } else {
                 $alreadyCompressedCounter++;
             }
             if ($overallCounter % 10 == 0) {
                 \Logger::debug("Waiting 5 secs to not kill the server...");
                 sleep(5);
             }
         }
         \Pimcore::collectGarbage();
         // check here how many already compressed versions we've found so far, if over 100 skip here
         // this is necessary to keep the load on the system low
         // is would be very unusual that older versions are not already compressed, so we assume that only new
         // versions need to be compressed, that's not perfect but a compromise we can (hopefully) live with.
         if ($alreadyCompressedCounter > 100) {
             \Logger::debug("Over " . $alreadyCompressedCounter . " versions were already compressed before, it doesn't seem that there are still uncompressed versions in the past, skip...");
             return;
         }
     }
 }
 function sql_backup()
 {
     vam_set_time_limit(0);
     $backup_file = DIR_FS_ADMIN_BACKUP . $this->cip_name . '.sql';
     // From original admin/backup.php:
     $fp = fopen($backup_file, 'w');
     $schema = '# Contrib Installer.' . "\n" . '# Makes customizing VaM Shop "simple".' . "\n" . '# Copyright (c) ' . date('Y') . ' Vlad Savitsky' . "\n" . '# http://vamshop.ru' . "\n" . '#' . "\n" . '# Database Backup For ' . STORE_NAME . "\n" . '#' . "\n" . '# Database: ' . DB_DATABASE . "\n" . '# Database Server: ' . DB_SERVER . "\n" . '#' . "\n" . '# Backup Date: ' . date(PHP_DATE_TIME_FORMAT) . "\n\n";
     fputs($fp, $schema);
     $tables_query = cip_db_query('show tables');
     while ($tables = vam_db_fetch_array($tables_query)) {
         list(, $table) = each($tables);
         $schema = 'drop table if exists `' . $table . '`;' . "\n" . 'create table `' . $table . '` (' . "\n";
         $table_list = array();
         $fields_query = cip_db_query("show fields from `" . $table . "`");
         while ($fields = vam_db_fetch_array($fields_query)) {
             $table_list[] = $fields['Field'];
             $schema .= '  `' . $fields['Field'] . '` ' . $fields['Type'];
             if (strlen($fields['Default']) > 0) {
                 $schema .= ' default \'' . $fields['Default'] . '\'';
             }
             if ($fields['Null'] != 'YES') {
                 $schema .= ' not null';
             }
             if (isset($fields['Extra'])) {
                 $schema .= ' ' . $fields['Extra'];
             }
             $schema .= ',' . "\n";
         }
         $schema = preg_replace("/,\n\$/", '', $schema);
         // add the keys
         $index = array();
         $keys_query = cip_db_query("show keys from `" . $table . "`");
         while ($keys = vam_db_fetch_array($keys_query)) {
             $kname = $keys['Key_name'];
             if (!isset($index[$kname])) {
                 $index[$kname] = array('unique' => !$keys['Non_unique'], 'columns' => array());
             }
             $index[$kname]['columns'][] = $keys['Column_name'];
             $index[$kname]['sub_part'][] = $keys['Sub_part'];
         }
         while (list($kname, $info) = each($index)) {
             $schema .= ',' . "\n";
             $columns = '';
             foreach ($info['columns'] as $id => $col) {
                 if ($columns == '') {
                     $columns .= "`" . $col . "`";
                 } else {
                     $columns .= ",`" . $col . "`";
                 }
                 if ($info['sub_part'][$id] != NULL && $info['sub_part'][$id] != 'NULL') {
                     $columns .= "(" . $info['sub_part'][$id] . ")";
                 }
             }
             if ($kname == 'PRIMARY') {
                 $schema .= '  PRIMARY KEY (' . $columns . ')';
             } elseif ($info['unique']) {
                 $schema .= '  UNIQUE `' . $kname . '` (' . $columns . ')';
             } else {
                 $schema .= '  KEY `' . $kname . '` (' . $columns . ')';
             }
         }
         $schema .= "\n" . ');' . "\n\n";
         fputs($fp, $schema);
         // dump the data
         $rows_query = cip_db_query("SELECT `" . implode('`, `', $table_list) . "` from `" . $table . "`");
         while ($rows = vam_db_fetch_array($rows_query)) {
             $schema = 'insert into `' . $table . '` (`' . implode('`, `', $table_list) . '`) values (';
             reset($table_list);
             while (list(, $i) = each($table_list)) {
                 if (!isset($rows[$i])) {
                     $schema .= 'NULL, ';
                 } elseif (vam_not_null($rows[$i])) {
                     $row = addslashes($rows[$i]);
                     $row = preg_replace("/\n#/", "\n" . '\\#', $row);
                     $schema .= '\'' . $row . '\', ';
                 } else {
                     $schema .= '\'\', ';
                 }
             }
             $schema = preg_replace('/, $/', '', $schema) . ');' . "\n";
             fputs($fp, $schema);
         }
     }
     fclose($fp);
     gzcompressfile($backup_file);
     if (is_file($backup_file)) {
         //chmod($backup_file, 0777);
         ci_remove($backup_file);
     }
     if (file_exists($backup_file . '.gz')) {
         chmod($backup_file . '.gz', 0777);
     }
 }
Beispiel #5
0
 /**
  *
  */
 public function cleanupLogFiles()
 {
     // rotate logs
     $logs = [PIMCORE_LOG_DEBUG, PIMCORE_LOG_DIRECTORY . "/php.log", PIMCORE_LOG_DIRECTORY . "/redirect.log", PIMCORE_LOG_DIRECTORY . "/legacy-class-names.log", PIMCORE_LOG_DIRECTORY . "/legacy-class-names-admin.log", PIMCORE_LOG_DIRECTORY . "/libreoffice-pdf-convert.log"];
     foreach ($logs as $log) {
         if (file_exists($log) && filesize($log) > 200000000) {
             // archive log (will be cleaned up by maintenance)
             rename($log, $log . "-archive-" . date("m-d-Y-H-i"));
             \Pimcore\File::put(PIMCORE_LOG_DEBUG, "");
         }
     }
     // archive and cleanup logs
     $files = glob(PIMCORE_LOG_DIRECTORY . "/*.log-archive-*");
     if (is_array($files)) {
         foreach ($files as $file) {
             if (filemtime($file) < time() - 86400 * 30) {
                 // we keep the logs for 30 days
                 unlink($file);
             } elseif (!preg_match("/\\.gz\$/", $file)) {
                 gzcompressfile($file);
                 unlink($file);
             }
         }
     }
 }
Beispiel #6
0
/**
 * Create database backup (cron task function).
 *
 * @param vivvo_lite_site	$sm
 */
function auto_backup($sm)
{
    include_once VIVVO_FS_INSTALL_ROOT . 'lib/backup/mysql_backup.php';
    $folder_name = VIVVO_FS_ROOT . 'backup/';
    $file_name = $folder_name . 'backup_details.csv';
    $max_rows = 5000;
    $total_rows = 0;
    $log = '';
    $backup_obj = new BackupMySQL();
    $basename = $backup_obj->database . date('-Ymd-Hi-') . md5(uniqid(VIVVO_URL, true)) . '.sql';
    $filename = $folder_name . $basename;
    $table_details = $backup_obj->GetTables($backup_obj->database);
    @unlink($filename . 'gz');
    $table_count = count($table_details);
    for ($count = 0; $count < $table_count; $count++) {
        list($table_name, $row_count) = explode(':', $table_details[$count]);
        $start = 0;
        while ($start < $row_count && $row_count != 0) {
            $end = $start + $max_rows;
            $str = $table_name . ':' . $row_count . "\r\n";
            $file_contents[$count] = $str;
            if ($backup_obj->Execute($filename, $backup_obj->database, $table_name, $start, 5000, $row_count) == false) {
                $e = $backup_obj->error;
                $log .= 'Auto Backup Error - Table: ' . $table_name . ', details: ' . $e . "\n";
                break;
            } else {
                $total_rows += $end;
                $fp = fopen($file_name, 'w');
                $fc = count($file_contents);
                for ($counter = 0; $counter < $fc; $counter++) {
                    fwrite($fp, $file_contents[$counter]);
                }
                fclose($fp);
            }
            //if ($total_rows >= $max_rows) break;
            $start += $max_rows;
        }
    }
    unset($count, $table_count, $table_name, $row_count, $start, $file_contents, $max_rows, $total_rows, $str, $backup_obj, $fp, $fc, $counter);
    if (gzcompressfile($filename, 9) === false) {
        $log .= 'Backup file created but cannot be gzipped.';
    } else {
        $log .= 'Backup created and successfully gzipped.';
        @unlink($filename);
    }
    if (defined('VIVVO_CRONJOB_MODE')) {
        echo 'auto_backup: ' . $log . PHP_EOL;
    } else {
        admin_log('(Cron task: Auto Backup)', $log);
    }
}