save() public method

Saves dump to the file.
public save ( $file ) : void
return void
Ejemplo n.º 1
0
 /**
  * @param string $fileNamePrefix
  * @param bool $removeBackupFileAtTheEnd
  * @throws \Exception
  * @throws IOException
  * @return ResultObject[]
  */
 public function backup($fileNamePrefix = null, $removeBackupFileAtTheEnd = false)
 {
     $storagePath = $this->prepareStoragePath($this->backupTempPath);
     $file = new DatabaseBackupFile($storagePath);
     if (!empty($fileNamePrefix)) {
         $file->setNamePrefix($fileNamePrefix);
     }
     $this->mysqlDump->save($file->getFilePath());
     $resultObjects = [];
     /** @var IDatabaseBackupHandler $handler */
     foreach ($this->backupHandlers as $handler) {
         $results = $handler->process($file);
         $resultObjects = array_merge($resultObjects, $results);
     }
     if ($removeBackupFileAtTheEnd === true) {
         $this->removeBackupFile($file);
     }
     return Arrays::flatten($resultObjects);
 }
Ejemplo n.º 2
0
 public function backupnupload()
 {
     // $cloud=new Cloud;
     $dump = new \MySQLDump(new \mysqli(config("database.connections.mysql.host"), config("database.connections.mysql.username"), config("database.connections.mysql.password"), config("database.connections.mysql.database")));
     $dump->save('export.sql.gz');
     $filename = "thinkmeritapi." . Carbon::now()->format('d-m-Y h.i.s A') . '.zip';
     \Log::info('Generating backup file - ' . $filename);
     // Get real path for our folder
     $rootPath = realpath(base_path());
     // Initialize archive object
     $zip = new \ZipArchive();
     $zip->open('public/' . $filename, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
     // Create recursive directory iterator
     /** @var SplFileInfo[] $files */
     $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootPath), \RecursiveIteratorIterator::LEAVES_ONLY);
     echo "Creating zip file.";
     foreach ($files as $name => $file) {
         // Skip directories (they would be added automatically)
         if (strpos($name, 'vendor') !== false || strpos($name, 'node_modules') !== false || strpos($name, 'cache') !== false) {
             continue;
         } else {
             if (!$file->isDir()) {
                 // Get real and relative path for current file
                 $filePath = $file->getRealPath();
                 $relativePath = substr($filePath, strlen($rootPath) + 1);
                 // Add current file to archive
                 $zip->addFile($filePath, $relativePath);
             }
         }
     }
     // Zip archive will be created only after closing object
     $zip->close();
     \Log::info('Completed making zip file - ' . $filename);
     echo "Uploading zip backup file.";
     \Log::info('Uploading backup zip - ' . $filename);
     $this->cloud->put($filename, file_get_contents('public/' . $filename));
     \Log::info('Uploading success - ' . $filename);
     unlink('public/' . $filename);
     unlink('export.sql.gz');
     return $filename . " backup file successfully generated.";
 }
Ejemplo n.º 3
0
 public function backupAction()
 {
     $log = $this->getServiceLocator()->get('log');
     $log->addInfo('备份数据' . "\t" . $this->getRequest()->getServer('REMOTE_ADDR') . "\t" . $this->getRequest()->getHeaders()->get('User-Agent')->getFieldValue());
     $dbconf = $this->getServiceLocator()->get('config')['mysqli'];
     $dump = new \MySQLDump(new \mysqli($dbconf['host'], $dbconf['username'], $dbconf['password'], $dbconf['dbname']));
     $filename = date("Y-m-d_H-i-s") . "-db.sql";
     $tmpFile = dirname(__FILE__) . "\\" . $filename;
     $dump->save($tmpFile);
     $body = new Message();
     $part = new Part();
     $part->setType(Mime::TYPE_OCTETSTREAM);
     $part->setContent(file_get_contents($tmpFile));
     $part->setDisposition(Mime::DISPOSITION_ATTACHMENT);
     $part->setFileName($filename);
     $part2 = new Part();
     $part2->setType(Mime::TYPE_TEXT);
     $part2->setContent('小秋来发数据了');
     $body->addPart($part);
     $body->addPart($part2);
     $newmessage = new \Zend\Mail\Message();
     $newmessage->addTo($this->getServiceLocator()->get('MailOptions')->getMailTo());
     $newmessage->addFrom($this->getServiceLocator()->get('MailOptions')->getMailFrom());
     $newmessage->setBody($body);
     $newmessage->setSubject('备份数据');
     $transport = new SmtpTransport();
     $options = new SmtpOptions($this->getServiceLocator()->get('config')['mail']);
     $transport->setOptions($options);
     try {
         $transport->send($newmessage);
         echo 1;
     } catch (\Exception $e) {
         echo -1;
     }
     exit;
 }
Ejemplo n.º 4
0
 function init()
 {
     parent::init();
     preg_match('|([a-z]+)://([^:]*)(:(.*))?@([A-Za-z0-9\\.-]*)' . '(/([0-9a-zA-Z_/\\.-]*))|', $this->app->getConfig('dsn'), $matches);
     $form = $this->add('Form');
     $form->addField('username');
     $form->addField('password', 'password');
     $form->addField('mysql_host')->set($matches[5]);
     $form->addField('mysql_user')->set($matches[2]);
     $form->addField('password', 'mysql_password')->set($matches[4]);
     $form->addField('mysql_db')->set($matches[7]);
     $form->onSubmit(function ($f) {
         if (!$this->app->auth->verifyCredentials($f['username'], $f['password'])) {
             $f->displayError('username', 'Sorry, you cant reset database');
         }
         try {
             $user = clone $this->app->auth->model;
             $this->api->db->beginTransaction();
             $this->app->db->dsql()->expr('SET FOREIGN_KEY_CHECKS = 0;')->execute();
             $this->app->resetDB = true;
             foreach ($this->app->xepan_addons as $addon) {
                 $this->app->xepan_app_initiators[$addon]->resetDB();
             }
             $this->app->db->dsql()->expr('SET FOREIGN_KEY_CHECKS = 1;')->execute();
             $this->api->db->commit();
         } catch (\Exception_StopInit $e) {
         } catch (\Exception $e) {
             $this->api->db->rollback();
             $this->app->auth->login($user);
             throw $e;
         }
         $dump = new \MySQLDump(new \mysqli($f['mysql_host'], $f['mysql_user'], $f['mysql_password'], $f['mysql_db']));
         $dump->save(getcwd() . '/../install.sql');
         return "SQL Generated";
     });
 }
Ejemplo n.º 5
0
        if ($mode & self::TRIGGERS) {
            $res = $this->connection->query("SHOW TRIGGERS LIKE '" . $this->connection->real_escape_string($table) . "'");
            if ($res->num_rows) {
                fwrite($handle, "DELIMITER ;;\n\n");
                while ($row = $res->fetch_assoc()) {
                    fwrite($handle, "CREATE TRIGGER {$this->delimite($row['Trigger'])} {$row['Timing']} {$row['Event']} ON {$delTable} FOR EACH ROW\n{$row['Statement']};;\n\n");
                }
                fwrite($handle, "DELIMITER ;\n\n");
            }
            $res->close();
        }
        fwrite($handle, "\n");
    }
    private function delimite($s)
    {
        return '`' . str_replace('`', '``', $s) . '`';
    }
}
$db_host = '$DB_HOST';
$db_port = '$DB_PORT';
if (!$db_port) {
    $db_port = ini_get("mysqli.default_port");
}
$db_user = '******';
$db_password = '******';
$db_name = '$DB_NAME';
$sql_dir = '$SQL_DIR';
$connection = new mysqli($db_host, $db_user, $db_password, $db_name, $db_port);
$dump = new MySQLDump($connection);
$dump->save($sql_dir . 'dump.sql');
Ejemplo n.º 6
0
 /**
  * @param $filePath
  * @throws Exception
  */
 public function save($filePath)
 {
     $this->mysqlDump->save($filePath);
 }
Ejemplo n.º 7
0
 private function mysqlDump($dumpname)
 {
     require_once root . "/resource/phpmysqldumper/MySQLDump.php";
     $dumper = new \MySQLDump(new \mysqli(property::getInstance()->get('db_host'), property::getInstance()->get('db_user'), property::getInstance()->get('db_pass'), property::getInstance()->get('db_name')));
     $dumper->save(root . $dumpname);
 }
Ejemplo n.º 8
0
<?php

/**
 * نسخ احتياطي لقاعدة البيانات
 * User: pc-sales
 * Date: 2‏/6‏/2016
 * Time: 4:09 م
 */
require 'Class/MySQLDump.php';
require 'config.php';
set_time_limit(0);
$time = microtime(TRUE);
ignore_user_abort(TRUE);
$dump = new MySQLDump(new mysqli($dataInfoArray['host'] . ":{$dataInfoArray['port']}", $dataInfoArray['username'], $dataInfoArray['password'], $dataInfoArray['db']));
$dump->save('C:/Users/win/OneDrive/AFix/AFix[' . date('Y-m-d--H-i-s') . '].sql.gz');
echo "تم اخذ نسخة احتياطية بنجاح ";
Ejemplo n.º 9
0
<?php

set_time_limit(0);
ignore_user_abort(TRUE);
require __DIR__ . '/../src/MySQLDump.php';
$time = -microtime(TRUE);
$dump = new MySQLDump(new mysqli('localhost', 'root', 'password', 'database'));
$dump->save('dump ' . date('Y-m-d H-i') . '.sql.gz');
$time += microtime(TRUE);
echo "FINISHED (in {$time} s)";