Portfolio
Scripts and Websites I've made using PHP and MySQL mainly.
Snippets
Code snippets and mini tutorials
Contact
Contact me if you have any questions or queries
Home / Snippets / backup_mysql_database
This section is new and undergoing snippet addition, as of 13/6/11
A quick and simple way to back your MySQL database up and save it to a ZIP file.
Of course keeping the backup on the same server isn't good practice, so you may want to send it to a different server, or attach it to an email and send it to yourself (if it's a small DB).
But anyway, that's a very quick way of doing it if you were wondering.
This section is new and undergoing snippet addition, as of 13/6/11
Backup MySQL Database
A quick and simple way to back your MySQL database up and save it to a ZIP file.
<?php
$datestamp = date("Y-m-d");
$filename = 'DB_'.$datestamp;
$command = "mysqldump -h localhost -u myDBuser --password=myDBpassword --all-databases | gzip > /path/to/backup/folder/$filename.sql.gz";
$result = passthru($command);
?>
Of course keeping the backup on the same server isn't good practice, so you may want to send it to a different server, or attach it to an email and send it to yourself (if it's a small DB).
But anyway, that's a very quick way of doing it if you were wondering.
Comments
No Comments Have Been Made


