opensupports/server/controllers/system/backup-database.php

45 lines
1.1 KiB
PHP
Raw Normal View History

<?php
use Ifsnop\Mysqldump as IMysqldump;
2017-04-18 02:09:16 +02:00
/**
* @api {post} /system/backup-database Backup database
2018-09-20 22:19:47 +02:00
* @apiVersion 4.3.0
2017-04-18 02:09:16 +02:00
*
* @apiName Backup database
*
* @apiGroup System
2017-04-18 02:09:16 +02:00
*
* @apiDescription This path does a backup of the database.
2017-04-18 02:09:16 +02:00
*
* @apiPermission staff3
2017-04-18 02:09:16 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiUse NO_PERMISSION
2018-07-02 20:36:06 +02:00
*
2017-04-22 03:33:17 +02:00
* @apiSuccess {File} file File of the backup
2017-04-18 02:09:16 +02:00
*
*/
class BackupDatabaseController extends Controller {
const PATH = '/backup-database';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'staff_3',
'requestData' => []
];
}
public function handler() {
$fileDownloader = FileDownloader::getInstance();
$fileDownloader->setFileName('backup.sql');
2018-07-02 20:36:06 +02:00
$mysqlDump = new IMysqldump\Mysqldump('mysql:host='. MYSQL_HOST . ';port=' . MYSQL_PORT . ';dbname=' . MYSQL_DATABASE , MYSQL_USER, MYSQL_PASSWORD);
$mysqlDump->start($fileDownloader->getFullFilePath());
if($fileDownloader->download()) {
$fileDownloader->eraseFile();
}
}
2018-07-02 20:36:06 +02:00
}