Welcome Guest, Not a member yet? Register   Sign In
backup database problem
#1

hi this is my controller :

Code:
public function backup_database(){

       $data=[];

       $oggi=date ("d-m-Y");

       // Load the DB utility class
       $this->load->dbutil();

       // Backup your entire database and assign it to a variable
       $backup = $this->dbutil->backup();

       $this->load->library('zip');

       // Load the file helper and write the file to your server
       $this->load->helper('file');

       if(write_file("backup_db/backup".$oggi.".txt", $backup)){
           $this->load->view('templates/header_admin');
           $this->load->view('templates/menu_admin');
           $this->load->view('admin/db_backup_ok', $data);
           $this->load->view('templates/footer_admin');


       }else{
          $this->load->view('templates/header_admin');
           $this->load->view('templates/menu_admin');
           $this->load->view('admin/db_backup_error', $data);
           $this->load->view('templates/footer_admin');

       }




   }

It work but the file made with this command have problem , if i set txt i have the document isn't a valid UTF-8 .
If i set zip , the archive cannot open ....

How can i solve ?
Reply
#2

Are you setting the backup preferences?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(01-18-2018, 04:47 AM)InsiteFX Wrote: Are you setting the backup preferences?

From docs :

Code:
Usage Example
// Load the DB utility class
$this->load->dbutil();

// Backup your entire database and assign it to a variable
$backup = $this->dbutil->backup();

// Load the file helper and write the file to your server
$this->load->helper('file');
write_file('/path/to/mybackup.gz', $backup);

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

Must i set the backup preferences ?  i have the output file but i cannot open it ....
Reply
#4

PHP Code:
$prefs = array(
 
       'tables'        => array('table1''table2'),   // Array of tables to backup.
 
       'ignore'        => array(),                     // List of tables to omit from the backup
 
       'format'        => 'txt'                      // gzip, zip, txt
 
       'filename'      => 'mybackup.sql'             // 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
);

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

Look at the filename and format parameters.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(01-18-2018, 10:05 AM)InsiteFX Wrote:
PHP Code:
$prefs = array(
 
       'tables'        => array('table1''table2'),   // Array of tables to backup.
 
       'ignore'        => array(),                     // List of tables to omit from the backup
 
       'format'        => 'txt'                      // gzip, zip, txt
 
       'filename'      => 'mybackup.sql'             // 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
);

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

Look at the filename and format parameters.

hi tanks, now work , this is my controller :

Code:
public function backup_database(){

       $data=[];

       $oggi=date ("d-m-Y");

       $this->load->dbutil();

       $prefs = array(    
               'format'      => 'zip',            
               'filename'    => 'my_db_backup.sql'
             );


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

       $db_name = 'backup-on-'. $oggi .'.zip';
       $save = 'backup_db/'.$db_name;

       $this->load->helper('file');
     

       if( write_file($save, $backup)){

           $this->load->helper('download');
           force_download($db_name, $backup);

           $this->load->view('templates/header_admin');
           $this->load->view('templates/menu_admin');
           $this->load->view('admin/db_backup_ok', $data);
           $this->load->view('templates/footer_admin');


       }else{
          $this->load->view('templates/header_admin');
           $this->load->view('templates/menu_admin');
           $this->load->view('admin/db_backup_error', $data);
           $this->load->view('templates/footer_admin');

       }




   }
Reply




Theme © iAndrew 2016 - Forum software by © MyBB