Created
May 30, 2022 09:05
-
-
Save mdestafadilah/e346c7995e469dd8bcdf7a99b5d60f07 to your computer and use it in GitHub Desktop.
BACKUP DB MYSQL DUMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$this->load->helper(array('url','file','download')); | |
$this->load->library('zip'); | |
$website = $this->load->database('website', TRUE); // the TRUE paramater tells CI that you'd like to return the database object. | |
$DBUSER=$website->username; | |
$DBPASSWD=$website->password; | |
$DATABASE=$website->database; | |
$HOSTNAME=$website->hostname; | |
$db_name = 'backup-on-' . date("Y-m-d-H-i-s") . '.sql'; | |
$backup_path = APPPATH.'/assets/backup/'; // this is the destination directory name | |
if (!file_exists($backup_path)) { | |
mkdir($backup_path, 0755, true); | |
} | |
$save = $backup_path.$db_name; | |
// Windows | |
$command = 'C:\laragon\bin\mysql\mysql-5.7.24-winx64\bin\mysqldump --opt --host='.$HOSTNAME.' -u '.$DBUSER.' -p'.$DBPASSWD.' '.$DATABASE.' > '.$save.' 2>&1'; | |
// Linux | |
// $command = 'mysqldump --opt --host='.$HOSTNAME.' -u '.$DBUSER.' -p'.$DBPASSWD.' '.$DATABASE.' > '.$save.' 2>&1'; | |
passthru( $command ); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment