<?php

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

/**
 * 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);
        }
        
        // Load the DB utility class
        $this->load->dbutil();

        $file_name = date('Y_m_d_H_i_') . $this->db->database. '.zip';

        $prefs = array(
            'tables' => array(), // Array of tables to backup.
            'ignore' => array(), // List of tables to omit from the backup
            'format' => 'zip', // gzip, zip, txt
            'filename' => $file_name, // File name - NEEDED ONLY WITH ZIP FILES
            'add_drop' => TRUE, // Whether to add DROP TABLE statements to backup file
            'add_insert' => TRUE, // Whether to add INSERT data to backup file
            'newline' => "\n" // Newline character used in backup file
        );

        $backup = & $this->dbutil->backup($prefs);

        // Load the download helper and send the file to your desktop
        $this->load->helper('download');
        force_download($file_name, $backup);
    }

}

