<?php
    if (!defined('BASEPATH')) exit('No direct script access allowed');
    class Databasebackup extends MY_Controller {
        
        function __construct() {
            parent::__construct();
        }
        
        public function index() {
            $data['template'] = 'settings/databasebackup_view';
            $this->load->view('template',$data);
        }
        
        public function downloadbackup() {
            $this->load->dbutil();
            $prefs = array(     
                'format'      => 'zip',             
                'filename'    => 'my_db_backup.sql'
            );
            $backup =& $this->dbutil->backup($prefs); 
            $db_name = 'backup-on-'. date("Y-m-d-H-i-s") .'.zip';
            $save = 'pathtobkfolder/'.$db_name;
            $this->load->helper('file');
            write_file($save, $backup); 
            $this->load->helper('download');
            force_download($db_name, $backup);
        }
        
    }