<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

include dirname(__DIR__) . '/libraries/shuttle/dumper.php';

/**
 * Description of backup
 *
 * @author Igor Ratsun
 */
class backup extends MX_Controller {

    public function backup_db() {
       // Acceess check
        if (!$this->rt_user->isAllowed('system', 'backup_db')) {
            show_404('', FALSE);
        }
        
        $dumper = Shuttle_Dumper::create(array(
            'host' => $this->db->hostname,
            'username' => $this->db->username,
            'password' => $this->db->password,
            'db_name' => $this->db->database,
        ));
        $file_name = date('Y_m_d_H_i_') . $this->db->database. '.sql.gz';
        $file_path = 'application/cache/' . $file_name;
        // Create backup
        $dumper->dump($file_path);
        // Load the download helper and send the file to your desktop
        $this->load->helper('download');
        force_download($file_name, file_get_contents($file_path));
    }

}

