/** * Restore the database from the restore folder * @param string $restore_dir */ public function restoreDB($restore_dir) { $restore_db_file = "{$restore_dir}/db/database_backup.sql"; if (!File::exists(stored_backups_path($restore_db_file))) { return; } $this->dbConnections(); $delimiter = "-- --------------------------------------------------------\n"; $fp = fopen($restore_db_file, 'r'); $buffer = ''; while (!feof($fp)) { // Read the sql files in chunks to avoid problems with large files $buffer .= fread($fp, 100); if (str_contains($buffer, $delimiter)) { list($statement, $extra) = explode($delimiter, $buffer, 2); $buffer = $extra; try { \DB::unprepared($statement); } catch (\Illuminate\Database\QueryException $e) { // Do nothing, if empty statement is occured } } } }
protected function backupDatabase() { if (!File::exists(stored_backups_path())) { File::makeDirectory(stored_backups_path()); } $this->current_time = date("Y-m-d-H-i-s"); $this->backup_file = stored_backups_path() . "/backup_{$this->current_time}.zip"; $synchronizer = new \Services\Synchronize($this); $synchronizer->startBackup(true, false, false); $backup_description = 'Backup created before installing ' . $this->config['name']; $synchronizer->saveBackupToDB($backup_description); }