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

49 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
* @apiVersion 4.1.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
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() {
global $mysql_host;
global $mysql_database;
global $mysql_user;
global $mysql_password;
$fileDownloader = FileDownloader::getInstance();
$fileDownloader->setFileName('backup.sql');
$mysqlDump = new IMysqldump\Mysqldump('mysql:host='. $mysql_host .';dbname=' . $mysql_database, $mysql_user, $mysql_password);
$mysqlDump->start($fileDownloader->getFullFilePath());
if($fileDownloader->download()) {
$fileDownloader->eraseFile();
}
}
}