Needed to create automated backup of sql file to a ftp server.
Below mentioned code i am using for the same
function backup_db()
{
ini_set('memory_limit','100G');
ini_set('max_input_time', 3000000);
ini_set('max_execution_time', 3000000);
error_reporting(E_ALL);
ini_set('display_errors', 1);
//echo 'here';exit;
$this->load->dbutil();
$this->load->helper(array('file', 'download'));
$prefs = array(
'tables' => array(), // Array of tables to backup.
'ignore' => array('general_ledger'), // List of tables to omit from the backup
'format' => 'zip', // 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' => "
" // Newline character used in backup file
);
//$this->db->save_queries = false;
$backup = $this->dbutil->backup($prefs);
//echo "in";exit();
$filename = 'backup-' . date('d_m_Y_H_i_s') . ' .zip';
write_file('/opt/backups/' . $filename, $backup);
//force_download($filename, $backup);
try{
$ftp_server = "xyz.xyz.xyz.xyz"; //server Ip
$ftp_conn = ftp_connect($ftp_server);
$ftp_username = "user";
$ftp_userpass = "pass";
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
// open file for reading
$file = "/opt/backups/".$filename;
$fp = fopen($file,"r");
// upload file
$success=ftp_fput($ftp_conn, "/Live_db_backups/Backup/$filename", $fp, FTP_ASCII);
// close this connection and file handler
ftp_close($ftp_conn);
fclose($fp);
}catch (Exception $e) {
$this->session->set_flashdata('error',"FTP Error for Db backup File Download!!!!");
echo 'FTP Bachup Failed';
}
echo 'here'; exit;
}
What actually happening in this code is only half of the database backup is being stored.
Complete database backup is not getting saved to a file.
Tried with increasing ini_set('memory_limit','100G');
ini_set('max_input_time', 3000000);
ini_set('max_execution_time', 3000000)
But still only half of the db value is storing.
What may be the issue?.
Any help appreciated.