I am using php to get backup of mysql database. On localhost it's working fine and the command is run as following:
$cmd = 'D:\xampp\mysql\bin\mysqldump --user=' .$db['username'].' --password= '. $db['password'] .' --host='.$db['host'].' '.$db['database'].' > '.FCPATH.$filename;
system($cmd,$return);
This works perfect when at localhost, but I want to this at godaddy hosting, so I don't know how to find the mysqldump path or how to store the .sql file.
at local my app directory is this http://localhost/backup_app/ and folder i am using to store is http://localhost/backup_app/DB_Backup but actual path that i given to store .sql file is using FCPATH ie D:\\xampp\\htdocs\\backup_app
and I don't know how to generate this path on godaddy.
Can anyone help?
You tagged to question with codeigniter. Once I done this. I am sharing the code with you, lets hope it will work for your version of CI.
In version 2.x, CI dbforge class not supporting to mysqli
driver, so I set the driver to mysql
.
$db['group_one']['dbdriver'] = 'mysql';
Define the path in constants to store the file.
define('ADMIN_DOCS_PATH','adminDocs/');
The code to take backup and store the file on disk.
public function getDatabaseBackup()
{
$this->db = $this->load->database('group_one', TRUE);
$this->load->dbutil();
$doc_name = 'DatabaseBackup'.date('YmdHis').'.sql.zip';
$prefs = array(
'tables' => array(), // Array of tables to backup.
'ignore' => array(), // List of tables to omit from the backup
'format' => 'zip', // gzip, zip, txt
'filename' => $doc_name, // 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);
$this->load->helper('file');
write_file('./'.ADMIN_DOCS_PATH.$doc_name, $backup);
}
Try this, also confirm your CI version and its support to dbforge
class to download the database dump.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.