Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backup SQL Table with php and Codeigniter

I want to backup a table in my database with codeigniter. I found this Guide, and programmed the function accordning to the Guide. The Problem is, that i dont get an error and i can't find the backup anywhere on my Server.

My function looks like this:

function backup_Eventtable() {
    $this->load->dbutil();
    $prefs = array(
            'tables'      => array('MYTABLE'),  // 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
          );

    $backup =& $this->dbutil->backup($prefs);
    //I tried it with and without the next 2 Lines.
    $this->load->helper('file');
    write_file('/uploads/EventBackup/mybackup.sql', $backup); 
}

I just checked the appache error log and found this line:

[Fri Mar 07 14:28:37 2014] [error] [client 192.168.242.116] PHP Fatal error:  Call to undefined method CI_DB_mysql_driver::backup() in /var/www/html/kaufleuten/admin/system/application/models/eventmodel.php on line 764, referer: http://devzh2.energy.local:8093/admin/events/edit/4002

database.php looks like this:

$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "myusername";
$db['default']['password'] = "mypassword";
$db['default']['database'] = "kaufleuten_typo3";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "/var/www/html/kaufleuten/admin/cache";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
like image 359
MrTouch Avatar asked Mar 21 '26 21:03

MrTouch


1 Answers

I had to enable the Codeigniter Log in the config.php. ($config['log_threshold'] = 2;) There I found the Error Log:

ERROR - 2014-03-07 15:33:35 --> Severity: Warning  --> fopen(uploads/EventBackup/mybackup.sql): failed to open stream: No such file or directory /var/www/html/kaufleuten/admin/system/helpers/file_helper.php 90

Changing the Path to:

 write_file('/var/www/html/kaufleuten/uploads/EventBackup/mybackup.sql', $backup);

resolved the Problem.

like image 155
MrTouch Avatar answered Mar 24 '26 12:03

MrTouch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!