0

I found that we can backup database by using Utility Class in Codeigniter. But i'am unable to do backup of MySql Stored Procedures.

My Question is:

How to backup MySql Database (including Stored procedures) by using Utility Class in CODEIGNITER.

Please help me. Thanks

Pradeep
  • 9,667
  • 13
  • 27
  • 34
  • By using above reference i am able to do backup of database but, MySql Stored Procedures are not Exported to backup file. – Koorma Ashok May 06 '18 at 17:24
  • First and foremost (anybody correct me if I am wrong), but I've never seen a backup script (and I've been through quite a few) that runs in PHP without exec and can backup stored procedures, so I'm not sure if it is something you can actually do. That being said I'm quite sure that the utility class **cannot** do this. I think your best bet is: https://stackoverflow.com/questions/6750531/using-a-php-file-to-generate-a-mysql-dump and http://www.logikdev.com/2011/03/01/how-to-dump-mysql-functions-and-stored-procedures/ – Alex May 06 '18 at 19:00

2 Answers2

0

try like this,

created file will be saved in your root folder and it will download automatically after created.

public function database_backup(){

     $this->load->helper('file');
     $this->load->helper('url');
     $this->load->helper('download');
     $this->load->library('zip');

     $this->load->dbutil();

     $db_format = [
         'format' => 'zip',
         'filename' => $this->db->database.'.sql'
     ];
     $backup =& $this->dbutil->backup($db_format);
     $db_name = 'database_backup.zip';
     $save = FCPATH . $db_name;

     // write the file to your server
     write_file($save, $backup); 

     // download the file
     force_download($db_name, $backup);

}

You can find information here : https://www.codeigniter.com/user_guide/database/utilities.html?highlight=write_file

Anfath Hifans
  • 1,588
  • 1
  • 11
  • 20
0

I found one solution: but, it doesn't belongs to codeigniter Database Utility Class

$file_name = 'blazonic_db_backup_' . date("d_m_Y_H_i_s") . '.zip';      
header( "Content-Type: application/zip" ); 
header( 'Content-Disposition: attachment; filename="' . $file_name . '"' );
$cmd = "mysqldump -u $user --password=$pwd $db -R | gzip --best"; 
passthru( $cmd );
exit(0);

Here -R is used to backup routines.