function backupAction() { check_demo(); if (!$this->_request->isPost()) { throw new Am_Exception_InputError("Backup can be runned by POST request only"); } $dat = date('Y_m_d-Hi'); $host = strtolower(preg_replace('/[^a-zA-Z0-9\\.]/', '', preg_replace('/^www\\./', '', $_SERVER['HTTP_HOST']))); $fn = "amember-{$host}-{$dat}.sql"; while (ob_get_level()) { ob_end_clean(); } $bp = new Am_BackupProcessor(); if ($bp->isGzip()) { header("Content-Type: application/x-gzip"); } else { header("Content-Type: text/sql"); } header("Content-Disposition: attachment; filename={$fn}" . ($bp->isGzip() ? ".gz" : "")); $stream = fopen('php://output', 'wb'); if (!$stream) { throw new Am_Exception_InternalError("Could not open php://output stream"); } $bp->run($stream); $this->getDi()->adminLogTable->log('Downloaded backup'); exit; // no any output later! }
function cronAction() { check_demo(); if (!$this->getDi()->config->get('email_backup_frequency')) { throw new Am_Exception_InternalError("Email Backup feature is disabled at Setup/Configuration -> Advanced"); } $key = $this->getParam('k'); if ($key != $this->getDi()->app->getSiteHash('backup-cron', 10)) { throw new Am_Exception_AccessDenied("Incorrect access key"); } $dat = date('Y_m_d'); $stream = fopen('php://temp', 'w+b'); if (!$stream) { throw new Am_Exception_InternalError("Could not open php://temp stream"); } $bp = new Am_BackupProcessor(); $stream = $bp->run($stream); rewind($stream); $filename = $bp->isGzip() ? "amember-{$dat}.sql.gz" : "amember-{$dat}.sql"; $mimeType = $bp->isGzip() ? 'application/x-gzip' : 'text/sql'; $m = new Am_Mail(); $m->addTo($this->getDi()->config->get('email_backup_address'))->setSubject('Email Backup ' . $dat)->setFrom($this->getDi()->config->get('admin_email')); $m->setBodyText(sprintf("File with backup for %s is attached. Backup was done at %s", $this->getDi()->config->get('root_url'), $this->getDi()->sqlDate)); $m->createAttachment($stream, $mimeType, Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $filename); $m->setPeriodic(Am_Mail::ADMIN_REQUESTED); $m->send(); $this->getDi()->adminLogTable->log('Email backup to ' . $this->getDi()->config->get('email_backup_address')); }