I want a PHP cron script to be set up with cPanel cron jobs that would take backup of MySQL database. Regards,
Execute the mysql dump command in your php script. example : function backup() { //PREPARE THE FILENAME USING DATA TIME $suffix = date('Y-m-d-h-i-s-a');; $filename = "backups/backup-$suffix.zip"; //CHECK WHETHER backups FOLDER EXISTS AND IS WRITEABLE if(! is_writable('backups')) { die('Backups folder not writable. Please check that backups folder exists and is writable'); } //Execute the command to create backup sql file exec("mysqldump --user={$this->username} --password={$this->password} --quick --add-drop-table --add-locks --extended-insert --lock-tables --all {$this->db} > backups/backup.sql"); //Now zip that file $zip = new ZipArchive(); if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) { exit("cannot open <$filename>\n"); } $zip->addFile("backups/backup.sql" , "backup.sql"); $zip->close(); #Now delete the .sql file if(! unlink("backups/backup.sql")) { die('backups/backup.sql temp file was not deleted. Please check'); } #Return the path to the zip backup file return $filename; } Now set cron to run this php script at desired intervals